Android ● ● ● Kotlin 2.0

Kodebits Day 48: Delegation By Keyword

Jun 28 2026
Practice delegation with a short kotlin challenge.

What does this print?

interface Calc {
  fun add(a: Int, b: Int): Int
}
class Base : Calc {
  override fun add(
    a: Int, b: Int
  ) = a + b
}
class Wrap(c: Calc) : Calc by c
fun main() {
  println(Wrap(Base()).add(2, 5))
}


Try it in the online Kotlin Playground →

[spoiler title="Solution"]

Answer:

7

Explanation:

by keyword delegates interface implementation to another object.

[/spoiler]


Further Reading