Novice Java, abstract class in interface

Novice Java, abstract class in interface

Due to the defect of single inheritance in java,
interfaces are needed to make up for this.

But regardless of interface or single inheritance,
you cannot have instantiated objects.
If you need to instantiate, you need to implement all the methods.
This means that even if there are many methods in it that you don't need, you have to implement all of the methods in order to instantiate the object;
even if it is an empty function body, nothing is done.
It will still make your code look ugly and not concise enough.
It seems to be just to achieve your purpose, and elegance disappears
. When there are more abstract methods in this abstract class,
such code is not only bloated, but also ugly.

Java can't ignore this fatal problem, and has to add a fig leaf;
when you encounter this dilemma again:
you might as well take a look at the method of instantiating this object. It may not only be new
but other construction methods will help you complete it. In fact, the ugly things, (all the methods that are not needed, are implemented with empty function bodies)
make your code still concise and elegant.

Guess you like

Origin blog.csdn.net/qq_45175218/article/details/102639858