Complete the delegate object in the code below so that passing it as an implementation would print "Hello Delegate".
Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features
Delegate
Hello, Delegate? Or are you Kotlin?
Report a typo
Sample Input 1:
Sample Output 1:
Hello DelegateWrite a program in Kotlin
// Do not change the code below!
interface IConsolePrinter {
val message: String
fun printMessage()
}
class BasicConsolePrinter(val x: String, val y: String) : IConsolePrinter {
override val message: String
get() = "$x $y"
override fun printMessage() {
print("Hello Kotlin")
}
}
class DerivedConsolePrinter(base: IConsolePrinter) : IConsolePrinter by base {
override fun printMessage() {
print(message)
}
}
fun main() {
val h = "Hello"
val d = "Delegate"
val k = "Kotlin"
// Do not change the code above!
val delegate = //?
// Do not change the code below!
val printer = DerivedConsolePrinter(delegate)
printer.printMessage()
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.