Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features

Standard delegates

Adulthood

Report a typo

Write a class Person that has an age property of type Int and an observable property isAdult of Boolean type that is updated whenever the value of the age property changes. The value of the isAdult property should be true if the person’s age is 18 or older and false otherwise.

Sample Input 1:

13

Sample Output 1:

false
Write a program in Kotlin
import kotlin.properties.Delegates

class Person {

// Declare here the delegated property: age

// Do not change the declaration of the property: isAdult
var isAdult: Boolean = false
private set
}
___

Create a free account to access the full topic