Recall & Review
beginner
What does the
open keyword mean in Kotlin?In Kotlin, <code>open</code> means a class or method can be inherited or overridden. By default, classes and methods are <code>final</code> and cannot be changed.Click to reveal answer
beginner
Why are classes and methods
final by default in Kotlin?Kotlin makes classes and methods
final by default to avoid accidental inheritance or overriding, which helps keep code safer and easier to understand.Click to reveal answer
beginner
How do you make a class inheritable in Kotlin?Add the <code>open</code> keyword before the class name. For example: <code>open class Animal</code> allows other classes to inherit from <code>Animal</code>.Click to reveal answer
beginner
How do you allow a method to be overridden in Kotlin?
Mark the method with
open. For example: open fun speak() {} lets subclasses provide their own version of speak().Click to reveal answer
beginner
What happens if you try to override a method that is not marked
open?Kotlin will give a compile error because only
open methods can be overridden. This prevents accidental changes to important behavior.Click to reveal answer
In Kotlin, what keyword do you use to allow a class to be inherited?
✗ Incorrect
The
open keyword allows a class to be inherited. Classes are final by default.What is the default behavior of classes in Kotlin regarding inheritance?
✗ Incorrect
By default, Kotlin classes are
final and cannot be inherited unless marked open.Which keyword allows a method to be overridden in Kotlin?
✗ Incorrect
The
open keyword marks a method as overridable. override is used when overriding.What happens if you try to override a method not marked as
open?✗ Incorrect
Kotlin prevents overriding methods that are not
open by giving a compile-time error.Which of these is true about
open classes and methods?✗ Incorrect
open means classes or methods can be inherited or overridden.Explain what the
open keyword does in Kotlin and why it is important.Think about how Kotlin protects your code by default and how <code>open</code> changes that.
You got /4 concepts.
Describe the difference between a class marked
open and one that is not in Kotlin.Focus on inheritance and overriding permissions.
You got /4 concepts.