Java – is there a case where the abstract class is better than the interface

I have a scenario in which several subclasses have similar implementations and some additional methods, and the implementation is different from each subclass I assume that abstract classes are a good choice for this situation But it would be better if the abstract class implemented an interface that contained all the method declarations Or I should stick with abstract classes

In short, I want to know that I prefer the scenario of abstract classes at the top of the hierarchy rather than at the interface

Solution

If your subclass has an is - a relationship with an abstract class, use an abstract class

You can have both abstract classes and interfaces - the abstract class that specifies the implementation and the interface that specifies the API

The collection framework is an example – it has the ArrayList extension abstractlist to implement list

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>