The difference between Java abstract class and interface
1. Abstract class and interface are two mechanisms in the Java language to support the definition of abstract classes
2. Take the abstract concept of door as an example, the door usually has open and close action, if only these, by the abstract class or interface to define all can, it seems that no problem.
3. But door should also have some abstract properties, such as state, size, shape, material, etc., which are not appropriate in the interface definition (Note: the member variable of interface must be public static final), should be used abstract class to define, so the abstract definition of the same thing/problem domain should be in abstract class, such as birds, shapes, etc.
4. Let's think about how to do a Alarmdoor class with alarm function, in the abstract class Riga alarm () method is not appropriate, because not all doors have alarm function, and can not define the abstract class alarm, Because Java does not allow multiple inheritance, this should be defined with interface, Alarmdoor implement Ialarm interface. So for a specific class to implement some of the new features, can be standardized by interface. The standardized Ialarm interface can also be used for other classes that require alarm functions, such as Alarmwindow.
The difference between Java abstract class and interface