Can any one explain me about getters and setters in detail with example | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can any one explain me about getters and setters in detail with example

3rd Dec 2016, 8:33 AM
CHUNDURU B M SIVA NAGA SAI
CHUNDURU B M SIVA NAGA SAI - avatar
3 Answers
+ 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.
3rd Dec 2016, 12:02 PM
Ousmane Diaw
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 }
3rd Dec 2016, 11:09 AM
Iwert
0
thanq
3rd Dec 2016, 1:22 PM
CHUNDURU B M SIVA NAGA SAI
CHUNDURU B M SIVA NAGA SAI - avatar