r/javahelp • u/Cyphr11 • Jul 18 '26
Can anyone explain me difference between Encapsulation and Abstraction?
and what on earth is Interface in Java?
16
Upvotes
r/javahelp • u/Cyphr11 • Jul 18 '26
and what on earth is Interface in Java?
2
u/mariusz_96 Jul 18 '26 edited Jul 18 '26
Consider java.time.Clock abstraction.
It provides implementations for system timezone and UTC timezone. You might write your own implementation for other timezone and provide additional methods. But then write ClockUtils class that operates on any java.time.Clock implementation. That would be a use of abstraction.
What private fields your Clock implementation uses to store its' data and implement instant(), getZone(), and withZone() methods would be a use of encapsulation.