0
what is the setter-getter?
plz anyone explain
3 Answers
+ 2
Setter is a method in a class to set a class member value which is hidden from outside. Getter is a method which returns class member value.
0
getColor(){
return color;
}
String color;
setColor(String blue){
color = blue
}
0
All class member should be private. But if you want to manipulate these members (for example from another class) you need some getter and setter methods which will manipulate or return these values.
Getter: get the member's value
Setter: set the member's value