javainterfaceabstract-classabstraction

How to achieve a full abstraction in Java without using interfaces?


I know that we can achieve 100% abstraction in Java with interfaces and partial abstraction with abstract classes.

In interview, the interviewer asked me to tell about any other way to achieve 100% abstraction except interfaces. Is there any other way?


Solution

  • One could use pure abstract classes with abstract methods only (no fields, no concrete methods).

    Edit: Note that starting with the addition of default methods in Java 8, interfaces are no longer necessarily 100% abstract.

    In the real world, abstract classes without fields (avoiding state distributed across the hierarchy) are probably more common than pure abstract classes.