Is it correct to infer that the default method is used in the interface to make it like an abstract class in Java?
•
Java
Since we now have default methods in the interface, is it more like an abstract class using both abstract and non abstract methods? In practice, can we use interfaces and abstract classes interchangeably? Is there a situation where the difference between the two is still relevant?
Solution
Yes, in some cases the differences between the two are still relevant
>The interface cannot contain fields (except static fields). > Interface cannot have constructor. > Interface cannot have final method. > Interfaces cannot have non - public methods
The first point is to really prevent you from using interfaces like classes Everyone else can solve it (though it may be ugly)
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
二维码