Abstract class and interface, abstract class Interface
Abstract class
Concept: Class modified by abstract keywords
Member features:
Constructor: Yes
Member variables: no restriction, both constant and variable
Member method: there are no restrictions, either abstract or abstract.
Relationships with classes: inheritance relationships
Subclass of an abstract class: either abstract or specific (all abstract methods must be implemented)
Tips: if an abstract method exists in a class, the current class must be defined as an abstract class.
Subclass of the abstract class:
Or all the abstract methods are called normal classes.
Or continue to abstract
Abstract classes cannot be directly instantiated ----> the only difference between an abstract class and a normal class is that you cannot create an instance object or allow abstract methods.
The normal subclass can be instantiated by polymorphism.
Interface
Concept: Java provides a standard interface
Definition Format: Permission modifier interface name {}
Member features:
Constructor: No
Member variable: can only be a constant. The default modifier is public static final.
Member method: only abstract methods are supported. The default modifier is public abstract.
Relationships with classes: Implementation relationships can be implemented in a single way.
Interface implementation class: either implement all abstract methods called normal classes or declare them as abstract classes
Interface implementation: the interface cannot be directly instantiated. You can create an object by instantiating the class according to the polymorphism.
Interfaces and interfaces are inherited from each other. They can be inherited from one or more interfaces.