Get and set

Report a typo

You have a class called QuizBox, which stores items (item) of some type. Also, this class has a field isChanged of type Boolean, which shows if an instance of QuizBox was changed. By default, it equals false. Change the standard get and set methods for the field item. When the get() method is invoked, it should print "You asked for the item" and return the item. When set() is invoked, you should set a new value of item,change isChanged to true and print "You changed the item".

Write a program in Kotlin
data class QuizBox<T>(val hiddenItem: T) {
var isChanged = false
var item: T = hiddenItem
// implement methods
get() {}
set(value) {}
}
___

Create a free account to access the full topic