Class that contains the abstract modifier is an abstract class, and the abstract class cannot create an instance object, and the classes containing the abstract method must be defined as abstract class, and the method in the abstract class does not have to be abstract. Abstract to define abstract methods must be implemented in a specific subclass, so ah, there can be no abstract constructor method or abstract static method, if the subclass does not implement all the methods in the abstract parent class, then the subclass must also be defined as an abstract class.
Interface (interface) can be said to be a special case of abstract classes. All methods in an interface must be abstract, and the method definition in the interface defaults to public abstract. The variables in the interface are global constants, which are public static final adornments.
Look at their grammatical differences!
1, the abstract class can have a construction method, and the interface cannot have a construction method.
2, abstract classes can have ordinary member variables, and interfaces cannot have ordinary member variables.
3, abstract classes can contain non-abstract ordinary methods, and all the methods in the interface must be abstract, not a non-abstract ordinary method.
4, the access type of an abstract method in an abstract class can be public, protected, and the default type, but the abstract method in the interface is only public type, and the default is the public abstract type.
5, a static method can be included in an abstract class, and a static method cannot be contained within an interface.
6, the abstract class and interface can contain static member variables, the access type of static member variables in the abstract class can be arbitrary, but the variables defined in the interface can only be public static type, and the default is the public static type.
7, a class can implement multiple interfaces, but can inherit only one abstract class.
Add the difference between the two in the application:
Interface is more in the system framework design method to play a role in the main definition of communication between modules, and abstract classes in the implementation of code to play a role, you can implement code reuse
The differences between abstract classes and interfaces in Java