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]