0
Can any one explain me about getters and setters in detail with example
3 Respostas
+ 1
Getters and Setters also known as accessor/mutator methods are simply used to allow a particular object to read or change a particular data within an object. This is actually known as Encapsulation which is another topic.
0
Getters and setters are methods that allow an object to change a variable. You can use these methods to change a value of a variable that is set to private (= can only be changed by something in the same class).
example:
some class{
private int x = 0;
getX(){bla bla}
setX(){bla bla}
}
Main class{
// this class cant get the value x so it needs the methods
int y = object.getX;
//the object used the method to get the private value from the other class -> y is now given the value of x
}
0
thanq