Complete the code to declare a sealed class named Shape.
sealed class [1]
The sealed class must be declared with the exact name Shape to match the requirement.
Complete the code to declare a subclass Circle of the sealed class Shape.
class Circle(val radius: Double) : [1]()
The subclass must inherit from the sealed class Shape using the exact class name.
Fix the error in the when expression to handle all subclasses of Shape.
fun area(shape: Shape): Double = when(shape) {
is Circle -> Math.PI * shape.radius * shape.radius
is Square -> shape.side * shape.side
[1] -> throw IllegalArgumentException("Unknown shape")
}The when expression requires an else branch to handle all other cases not explicitly matched.
Fill both blanks to declare a sealed class Shape with two subclasses Circle and Square.
sealed class [1] { class Circle(val radius: Double) : [2]() class Square(val side: Double) : Shape() }
Both the sealed class and the superclass in the subclasses must be named Shape exactly.
Fill all three blanks to create a sealed class Shape with subclasses Circle and Square, and a function to calculate area.
sealed class [1] { class Circle(val radius: Double) : [2]() class Square(val side: Double) : Shape() } fun area(shape: [3]): Double = when(shape) { is Circle -> Math.PI * shape.radius * shape.radius is Square -> shape.side * shape.side }
The sealed class and its subclasses must use the exact name Shape. The function parameter type must also be Shape.