What is the difference between abstract class and interface?
Class that contains the abstract modifier is an abstract class, an instance object that the abstract class cannot create. Classes containing the abstract method must be
Methods that are defined as abstract Class,abstract class classes do not have to be abstract. The abstract class defines an abstraction method that must be
Must be implemented in a specific (concrete) subclass (the normal method in an abstract class can be implemented without the need to implement it.) Therefore, there can be no abstract construction party
method or abstract static methods. If the subclass does not implement all the abstract methods in the abstract parent class, then the subclass must also be defined as an abstract type.
An interface (interface) can be described as a special case of an abstract class, and all methods in an interface must be abstract.
The method definition in the interface defaults to the public abstract type, and the member variable type in the interface defaults to public static final.
Abstract methods
Abstract method: A method that does not have a method body in a class is an abstract method.
Methods in an interface are abstract methods
You define a non-abstract method, which is also an abstract method by default, and the implementation class must be rewritten,
You just omit the keyword abstract and actually the interface will automatically add to you
1 Interfacealarm{2 Public Abstract voidAlarm ();//Default is abstract3 }4 Abstract classdoor{5 Public Abstract voidOpen ();//missing default is abstract6 Public Abstract voidclose ();7 }8 classAlarmdoorextendsDoorImplementsalarm{9 Public voidOpen () {Ten One } A Public voidClose () { - - } the Public voidAlarm () { - - } - } + -
Abstract class-interface--some explanations of abstract methods