Predict the output
What does this print?
interface Greeter { fun greet() = "hi" }
abstract class Named(val name: String)
class Bot : Named("bot"), Greeter
fun main() {
val b = Bot()
println("${b.greet()} ${b.name}")
}Hint 1 of 1
Interfaces can have default bodies.
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A hi bot
Correct. Bot gets the default greet() from the interface and name from the abstract class.
Why not the others?
- B It doesn't compile. A class can extend one class and implement interfaces.
- C bot hi. Check the order in the string.
- D null bot. greet() has a default body.