In the provided code below, modify the declaration of the property area so it should only be calculated when it is first accessed.
Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features
Standard delegates
Only once
Report a typo
Sample Input 1:
5Sample Output 1:
First time: 25.0
25.0Write a program in Kotlin
class Square(val x: Double) {
val area: Double
get() {
print("First time: ")
return x * x
}
}
___
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.