File a copy of the difference between abstract classes and interfaces in java

Abstract class

Features:

1. Methods can be constructed in abstract classes

2. Common attributes, methods, static attributes and methods can exist in abstract classes. But it cannot be calculated directly.

3. Abstract methods can exist in abstract classes.

4. If there is an abstract method in a class, then the current class must be an abstract class; an abstract class does not necessarily have an abstract method.

5. The abstract method in an abstract class needs to be implemented by a subclass. If the subclass does not implement it, the subclass also needs to be defined as abstract.

6. Can not be used with final, because final classes cannot be rewritten and inherited,

interface

1. There are only method declarations in the interface, and no method body. But after J8, when you need to write the method body, you must add default or static

2. There are only constants in the interface, because the defined variables will be added by default when compiling

public static final 

3. The methods in the interface are always decorated by public.

4. There is no construction method in the interface, nor can the objects of the interface be instantiated.

5. Interface can achieve multiple inheritance

6. The methods defined in the interface need to be implemented by the implementation class. If the implementation class cannot implement all the methods in the interface, it can be written as abstract

The implementation class is defined as an abstract class.

Guess you like

Origin blog.csdn.net/NICVSY/article/details/109431000