Recall & Review
beginner
What is an interface with default implementations in Kotlin?
An interface in Kotlin can have methods with default implementations. This means you can define a function inside an interface with a body, so classes implementing the interface don't have to provide their own version unless they want to override it.
Click to reveal answer
beginner
How do you declare a function with a default implementation inside a Kotlin interface?
Inside the interface, you write the function with its body, like this:<br>
interface MyInterface {
fun greet() {
println("Hello from interface")
}
}Click to reveal answer
beginner
Can a class that implements an interface with default implementations choose to override those methods?Yes. The class can use the default implementation or provide its own version by overriding the method.Click to reveal answer
intermediate
Why are default implementations in interfaces useful?
They let you add new functions to interfaces without breaking existing classes. Classes can use the default code or customize it, making code easier to maintain and extend.Click to reveal answer
intermediate
What happens if two interfaces with the same default method are implemented by a class?
The class must override the conflicting method and provide its own implementation to resolve the conflict.Click to reveal answer
In Kotlin, how do you provide a default implementation for a method in an interface?
✗ Incorrect
In Kotlin, you simply write the method with its body inside the interface to provide a default implementation.
If a class implements an interface with a default method, what can it do?
✗ Incorrect
The class can choose to use the default implementation or override it with its own.
What must a class do if it implements two interfaces that have the same default method?
✗ Incorrect
The class must override the conflicting method to resolve ambiguity.
Why are default implementations in interfaces helpful?
✗ Incorrect
Default implementations let you add new methods to interfaces without forcing all classes to change.
Which keyword is NOT used when defining default implementations in Kotlin interfaces?
✗ Incorrect
Kotlin does not use the 'default' keyword for interface methods with implementations.
Explain how Kotlin interfaces support default implementations and why this feature is useful.
Think about how interfaces can have code inside them and how classes can use or change that code.
You got /4 concepts.
Describe what happens when a class implements two interfaces that have the same default method.
Consider how Kotlin handles multiple inheritance of behavior.
You got /3 concepts.