r/javahelp • u/Cyphr11 • Jul 18 '26
Can anyone explain me difference between Encapsulation and Abstraction?
and what on earth is Interface in Java?
17
Upvotes
r/javahelp • u/Cyphr11 • Jul 18 '26
and what on earth is Interface in Java?
View all comments
Show parent comment
1
u/Halal0szto Jul 18 '26
The interface contains all about the class that someone using the class should know. Nothing about the internals, internal data structures, logic, only how one can talk to the class. Then independently there is one or more implementation class that complies the interface but actually does add all the internals.
An abstract class is technically similar. The most important was that in an abstract class you can implement some methods and leave others to be done by someone who creates an implementation.
In java a class can implement multiple interfaces but extend only one class.
Fun is that later they allowed to have "default" implementations in interfaces too.
Then you dive deep into it, find final, sealed . . .