Friday, July 10, 2015

Setters and Getters

Note: To make use of private variables of called class in calling class, we use getter and setter methods concept.

- To get and set values to the class variables(that are set as private) from other class we use get and set methods(these are public) in the parent class.

- No need to getters and setters manually, eclipse has inbuilt feature to do so

- Set the class variables as private, but to access the variables outside the class you need to create getters and setters

- Right click on the code -> Source -> Generate Getters and Setters -> this will create getter and setter methods in the code.

- keyword--- this ---- to assign class level variable

- Getter and Setter will help you understand Encapsulation, as you are hiding the data.


Miscellaneous:

- How do you think Getters and Setting will hide the values or help for encapsulation?   ---- not sovled

-

No comments:

Post a Comment