Quiz: Extensions

Test your understanding of the concepts discussed in this chapter.

1

What is the output of the following code?

open class View
class Button : View()

fun View.printMe() {
    println("I'm a View")
}

fun Button.printMe() {
    println("I'm a Button")
}

fun main() {
    val button: Button = Button()
    button.printMe() 
    val view: View = button
    view.printMe() 
}
A)
I'm a Button
I'm a Button
B)
I'm a View
I'm a Button
C)
I'm a Button
I'm a View
D)
I'm a View
I'm a View
Question 1 of 50 attempted

Get hands-on with 1400+ tech skills courses.