Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features

Standard delegates

Only once

Report a typo

In the provided code below, modify the declaration of the property area so it should only be calculated when it is first accessed.

Sample Input 1:

5

Sample Output 1:

First time: 25.0
25.0
Write a program in Kotlin
class Square(val x: Double) {
val area: Double
get() {
print("First time: ")
return x * x
}
}
___

Create a free account to access the full topic