Skip to main content


Showing posts from September, 2015

Encapsulation in Practical.

Encapsulation is one of the four fundamental OOP concepts.Encapsulation is the technique  to Provide the ability to a program to hind their internal characteristics and behaviorof by  creating
private fields in class and providing access to them via public methods.
If a field is declared private, it cannot be accessed by anyone outside the class,
thereby hiding the fields within the class.So encapsulation  protect them by unauthorized access / party  by creating a protecting wrapper around your code and data.

Encapsulation can be described as a protective barrier that prevents the code and data being
randomly accessed by other code defined outside the class.
The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.

For Example

We have a data class with two fields name and id

public class Result{

   private String name;