Friday, 8 January 2016

Encapsulation in java

Encapsulation :

 - Definition:
    : Encapsulation is a process of wrapping code/data(variables) and data together into a single unit.
    : Hiding the implementation and showing functionality
 - We can create a fully encapsulated class in java by making all the data memebers of class as "Private" . Ex: private String name;
 - By using only setter and getter methods you can make changes.
 - Example for Encapsulation : Capsule(medicine/capsule mixed with several medicines).
 - Ex: Suppose if u want to set the value of ID greater than 100 only, then u can write the
       logic inside the setter method.


Example Code:

No comments:

Post a Comment