1Abstract classes and interfaces cannot be directly instantiated. to instantiate an abstract class, the variable must point to the subclass object that implements all abstract methods, and the interface variable must point to the class object that implements all interface methods.
2Abstract classes must be inherited by quilt classes, and interfaces must be implemented by classes.
3The interface can only be used for method declaration. The abstract class can be used for method declaration or method implementation.
4The variables defined in the interface can only be public static constants, and the variables in the abstract class are common variables.
5Abstract METHODS in abstract classes must be implemented by all quilt classes. If not all child classes can implement the parent class abstract methods, this child class can only be an abstract class. Similarly, if an interface cannot be fully implemented, the class can only be an abstract class.
6Abstract METHODS can only be declared and cannot be implemented.Abstract void ABC ();Cannot be writtenAbstract void ABC (){}.
7Abstract classes can have no abstract methods
8If an abstract method exists in a class, the class can only be an abstract class.
9Abstract methods must be implemented, so they cannot be static or private.
10Interfaces can inherit interfaces and can inherit multiple interfaces
So when to use inheritance and when to use interfaces?
Java Interfaces are used to share common behaviors among different class instances. (Method header only).
Inheritance is used to share common code in related class instances. (Including data members and Methods)
In your program design, remember to useJavaInterfaces share common behaviors. Use inheritance with common code .