0

How can I get 50 as the output

From the initializer block, I want to add the local variable age to the A.age member so that 50 is printed to the console. How can I reference A.age in this sample https://code.sololearn.com/cLpfLU7GBgJn/?ref=app

2nd Jul 2023, 10:31 AM
RuntimeTerror
RuntimeTerror - avatar
2 Antworten
+ 2
if U want to add 25 to the A age variable you can use the super keyword: println(age + super.age)
2nd Jul 2023, 11:02 AM
Sultan Khalid
Sultan Khalid - avatar
+ 2
init { val age = 25 println(this.age + age) }
2nd Jul 2023, 2:21 PM
A͢J
A͢J - avatar