Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlinsealed class hierarchiesSingle-choice MCQ

What does this code print, using a sealed hierarchy whose root has a private primary constructor?

sealed class Shape private constructor(val sides: Int) { object Circle : Shape(0) class Polygon(sides: Int) : Shape(sides) } fun label(s: Shape) = when (s) { Shape.Circle -> "circle" is Shape.Polygon -> "poly-${s.sides}" } fun main() { println(label(Shape.Polygon(3))) }