Skip to main content

Encapsulation in Java || What is Encapsulation in Java?

 Encapsulation in Java || What is Encapsulation in Java?

Hi , Welcome to Java Education Point. In this post we talk about Encapsulation in java.

Defination of Encapsulation:

Binding of data and corresponding methods into a single unit is called Encapsulation . 

If any java class follows data hiding and abstraction such type of class is said to be encapsulated class.

Encapsulation-in-java

Encapsulation=Datahiding+Abstraction

  Encapsulation-in-java

Every data member should be declared as private and for every member we have to maintain getter & Setter methods. 

Example of Encapsulation:

Example-of-Encapsulation

Advantages of Encapsulation:

The main advantages of encapsulation are : 

1. We can achieve security. 

2. Enhancement will become very easy. 

3. It improves maintainability and modularity of the application. 

4. It provides flexibility to the user to use system very easily. 

The main disadvantage of encapsulation is it increases length of the code and slows down execution. 

Comments