The difference between the Java interfaces and abstract classes?

Abstract class

Abstract class must be abstractmodified, subclasses must implement the abstract methods abstract class, if there is not achieved, then the subclass must also be modified by abstract. Abstract class default permissions for the modifier publiccan be defined as a public or procted, if defined as private, then the subclass can not inherit. An abstract class can not create object

The difference between abstract classes and ordinary classes

  1. Abstract class must be public, procted modification (if private modification, then the subclass can not inherit, it can not achieve its abstract method). The default is public by default
  2. An abstract class can not create object
  3. If a subclass inherits an abstract class, it must implement all its abstract methods. If there is an abstract method is not implemented, then it must be defined as abstract

interface

Using implicit variable interface public static finalmodification, and needs to be given an initial value. Implicit method of using public statica modified (and can only be public, if it is private, procted, then compile error). The method can not have a default interface specific implementations (JDK1.8 can start with a default implementation)

The difference between abstract classes and interfaces

  1. Abstract classes can inherit only once, but can implement multiple interfaces
  2. Interfaces and abstract classes must implement all the methods in which, if an abstract class abstract method is not implemented, then the need to define a subclass of abstract class. You can have non-abstract methods abstract class
  3. Interface with public static final variables must be modified, and the need to give the initial values. Therefore, the implementation class can not be redefined, not change its value.
  4. The default interface methods are public abstract, can only be of this type. Can not be static, the method does not allow interface override subclass, the abstract class allows static methods

Guess you like

Origin www.cnblogs.com/zzfpz/p/10990210.html