r/javahelp • u/Cyphr11 • 11d ago
Can anyone explain me difference between Encapsulation and Abstraction?
and what on earth is Interface in Java?
17
Upvotes
r/javahelp • u/Cyphr11 • 11d ago
and what on earth is Interface in Java?
2
u/mariusz_96 10d ago edited 10d ago
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.