The commonalities and differences between interfaces and abstract classes

Commonness:

  1. None can be instantiated

  2. Subclasses of the implementation class or abstract class in the interface can only be instantiated after implementing the method in the interface or abstract class

the difference:

  1. The interface only has the method definition. After JDK1.8, the default method body can be defined, and the abstract class can be defined or implemented.

  2. The implementation and inheritance keywords are different. Java only supports single inheritance but supports multiple implementations

  3. The interface emphasizes the realization of specific functions, which is convenient for the addition and deletion of the subsequent sequence. The abstract class emphasizes the belonging relationship and tends to the public class, which is not suitable for modification.

  4. The interface member variables default to public static final and must be assigned initial values. All member methods are public and abstract. Member variables in abstract classes default to default, which can be redefined or assigned in subclasses. Abstract methods are modified by abstract and cannot be Modified by private, static, synchronized, native.

 

Guess you like

Origin www.cnblogs.com/dretrtg/p/12739997.html