Android ● ● ○ Kotlin 2.0

Kodebits Day 35: Companion Object

Jun 5 2026
Practice objects with a short kotlin challenge.

What is the output?

class Box {
  companion object {
    val max = 10
    fun cap(n: Int) =
      if (n > max) max else n
  }
}
fun main() {
  println(Box.cap(15))
}


Try it in the online Kotlin Playground →

[spoiler title="Solution"]

Answer:

10

Explanation:

Companion objects provide class-level functions and properties.

[/spoiler]


Further Reading