As if inheritance conflicts weren't enough... delegate tricks and features

Report a typo

Suppose you have an interface, two slightly different implementations of the said interface, and a class with a delegate to spice it all up. Below, you are given four possible calls to the system, and your task is to match them with what these calls will print.

interface A {
    fun printA() = println("It's A")
    val msg: String
}

class B : A {
    override fun printA() = println(msg)
    override val msg: String = "It's B"
}

class C : A {
    override val msg: String = "it's C"
}

class D(base: A) : A by base {
    override val msg = "It's D"
    fun printB() = println(msg)
}
Match the items from left and right columns

C().printA()

D(B()).printB()

D(B()).printA()

println(C().msg)

It's B

It's C

It's D

It's A

___

Create a free account to access the full topic