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

Popular posts from this blog

Tightly Encapsulated class in Java || What is Tightly Encapsulated class in Java?

 Tightly Encapsulated class in Java || What is Tightly Encapsulated class in Java? 'Hi , Welcome to  Java Education Point . In this post we talk about Tightly Encapsulated class in java. Defination of Tightly Encapsulated Class: A class is said to be tightly encapsulated if and only if every variable of that class declared as private whether the variable has getter and setter methods are not , and whether these methods declared as public or not, these checkings are not required to perform. Example of Tightly Encapsulated Class: class Account  {  private double balance; public double getBalance() {  return balance;  }  }  Which of the following classes are tightly encapsulated? Which of the following classes are tightly encapsulated?  class A {  int x=10; //not  }  class B extends A  {  private int y=20; //not  }  class C extends B {  private int z=30; //not  }  Note: if the parent class is no...