Explain to the best of your ability the difference between setters and getters and why we need them. -JAVA
data members are declared as private in java. so, that they can't be accessed/modified directly by other classes in the project. this is called encapsulation. but if want to allow modification, access for these members we need some other way. that's why we create public methods to allow that. getters, get method for the private data member, which gives the value of that data member. setters, set method to change that private member, which sets the value of that data member.
Get Answers For Free
Most questions answered within 1 hours.