Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumKotlinclass delegation bySingle-choice MCQ

A class implements an interface using delegation `by` an instance, but also overrides one of the interface's methods directly in the class body. When code calls the *non-overridden* methods of the interface, which behavior is correct?

interface Worker { fun work(): String fun rest(): String } class DefaultWorker : Worker { override fun work() = "working" override fun rest() = "resting (default)" } class Manager(w: Worker) : Worker by w { override fun rest() = "managing" } fun main() { val m = Manager(DefaultWorker()) println(m.work() + " / " + m.rest()) }