The difference between Java abstract classes and interfaces

Abstract class features: 1 Methods can be constructed in abstract classes Abstract classes can have ordinary properties, methods, static properties and methods. 3. Abstract methods can exist in abstract classes. 4. If there is an abstract method in a class, the current class must be an abstract class; Abstract classes do not necessarily have abstract methods. 5. Abstract methods in abstract classes need to be implemented by subclasses. If subclasses do not implement, subclasses also need to be defined as abstract. Interface 1 In the interface, there are only method declarations and no method bodies. 2. There are only constants in the interface, because the defined variables will be added with public static final 3 by default during compilation The methods in the interface are always modified by public. 4. There is no construction method in the interface, and the object of the interface cannot be instantiated. 5. The interface can realize multi inheritance 6 The methods defined in the interface need to be implemented by an implementation class. If the implementation class cannot implement all the methods in the interface 7 The implementation class is defined as an abstract class.

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
分享
二维码
< <上一篇
下一篇>>