Challenge 3: Sealed Class with when — Solution sealed class Shape data class Circle(val radius: Double) : Shape() data class Square(val side: Double) : Shape() data class Rectangle(val width: Double, val height: Double) : Shape() fun area(shape: Shape): Double = when (shape) { is Circle -> Math.PI * shape.radius * shape.radius is Square -> shape.side * shape.side is Rectangle -> shape.width * shape.height } fun main() { println(area(Circle(3.0))) println(area(Square(4.0))) println(area(Rectangle(5.0, 2.0))) } /* Output: 28.274333882308138 16.0 10.0 Notes: - Shape is sealed, so Kotlin knows Circle, Square, and Rectangle are the only possible subclasses in existence. The "when" expression covers all three with "is" branches and needs no "else" — it's exhaustive. - If a fourth Shape subclass were added later without updating this "when", the code would fail to compile until a branch for it was added — catching the gap immediately instead of silently falling through. - Each "is X ->" branch smart-casts shape to that specific subtype, so shape.radius / shape.side / shape.width and .height are all accessible directly, with no manual casting. */