Difference between Abstraction and encapsulation
- Abstraction focuses on the outside view of an object (i.e. the interface) Encapsulation (information hiding) prevents clients from seeing it’s inside view, where the behavior of the abstraction is implemented.
- Abstraction solves the problem in the design side while Encapsulation is the Implementation.
- Encapsulation is the deliverable of Abstraction. Encapsulation barely talks about grouping up your abstraction to suit the developer needs.
eg . public interface ABC {
void display();
}
Here abstraction is provided by the interface meaning it will be the face of the class implementing the interface ABC
Encapsulation can be done as
public class DEF implements ABC{
void display(){
System.out.println("DEF");
}
}
In the above example
Inteface ABC provides abstraction , while class DEF provides encapsulation i.e. binding the data and the code together.
No comments:
Post a Comment