void main() {
House house1 = new House(4,2);
house1.aboutHouse();
print(house1.rooms);
house1.rooms = 10;
house1.aboutHouse();
}
class House {
// private variable
int _rooms;
int _floors;
House(this._rooms, this._floors);
void aboutHouse(){
print('This house has $_floors floors and $_rooms rooms.');
}
int get rooms{
return this._rooms;
}
set rooms(int room){
this._rooms = room;
}
}
--------------------------------------------[result]
This house has 2 floors and 4 rooms.
4
This house has 2 floors and 10 rooms.