Write a class Student that has a name property of type String and a notNull property id of type Int. The value of the id property must be initialized before it is accessed, and if an attempt is made to access it before it is initialized, an exception should be thrown.
Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming features
Standard delegates
Student
Report a typo
Sample Input 1:
10Sample Output 1:
Property id should be initialized before get.
10Write a program in Kotlin
import kotlin.properties.Delegates
class Student {
// Write your code here
}
// Do not change the code below
fun main() {
val student = Student()
val id = readln().toInt()
try {
println(student.id)
} catch (e: Exception) {
println(e.message)
}
student.id = id
println(student.id)
}
___
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.