Getters and setters are used to protect your data, particularly when creating classes . For each instance variable, a getter method returns its value while a setter method sets or updates its value. Given this, getters and setters are also known as accessors and mutators, respectively.
Read moreWhat is getter and setter?
Getters and Setters play an important role in retrieving and updating the value of a variable outside the encapsulating class. A setter updates the value of a variable, while a getter reads the value of a variable .
Read moreWhat is getter and setter in C++?
The getter function is used to retrieve the variable value and the setter function is used to set the variable value . Remember: You can directly access public member variables, but private member variables are not accessible.
Read more