Tuesday, 17 November 2015

What is Encapsulation ? Give an example of Encapsulation

Encapsulation means hiding/wrapping the data and methods in to a single unit. It prevents other objects from directly altering/modifying/accessing the properties or methods of the encapsulated object.
We can create fully encapsulated class by making the entire data member will be private and create getter, setter method to access that data member.
POJO/Java Bean class is the best example of fully encapsulated class.

No comments:

Post a Comment