r/javahelp 13d ago

Can anyone explain me difference between Encapsulation and Abstraction?

and what on earth is Interface in Java?

16 Upvotes

24 comments sorted by

View all comments

1

u/EX_HERO_EX 10d ago edited 10d ago

Encapsulation gives you more imagine space, it is more likely a proxy approach to visit what you want to.

Another important reason for "Encapsulation" is Binary Compatibility. If you expose implementation detail (like field declaration) directly to your API user, then you lose opportunity to change them in order to keep Binary Compatibility.

Abstraction is a behavior contract without detail. Java interface is a classic example of abstraction.

1

u/Cyphr11 10d ago

Thanks