Full abstraction in java without interfaces

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

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

+5
source share
3 answers

Pure abstract classes can only be used with abstract methods (no fields, no concrete methods).

Change Note: starting with adding default methods in Java 8, interfaces are no longer necessarily 100% abstract.

In the real world, fieldless abstract classes (avoiding a hierarchical state) are probably more common than pure abstract classes.

+4
source

Use abstract classes that have no implemented methods. These pure abstract classes, such as interfaces, have a null implementation.

If you want to learn about pure abstract classes and why they can be used instead of interfaces, you can read a pure abstract class and interface .

+7
source

You have already received your answer, I think, as Stefan mentioned. However, I would like to add that the goal of creating abstract classes is to protect the developer to write the same methods for different classes and increase reuse.

+1
source

Source: https://habr.com/ru/post/1263136/


All Articles