Differences between abstract classes and interfaces in Java
Abstract class:
The class containing the abstract modifier is an abstract class,
Abstract class cannot create instance objects,
Classes containing abstract methods must be defined as abstract class,
Abstract METHODS in class do not need to be abstract,
ABSTRACT To define abstract methods must be implemented in specific sub-classes. ThereforeAbstract constructor or abstract static methodIf the subclass does not implement all methods in the abstract parent class, the subclass must also be defined as an abstract class.
Interface:
An interface can be a special case of an abstract class. All methods in the interface must be abstract. The method definition in the interface is public abstract by default. The variables in the interface are global constants, I .e. public static final.
Syntax differences:
1. There can be constructor in the abstract class, and no constructor in the interface.
2. abstract classes can contain common member variables, but interfaces cannot contain common member variables.
3. abstract classes can contain non-Abstract Common methods. All methods in interfaces must be abstract and cannot have non-Abstract Common methods.
4. The access type of abstract methods in abstract classes can be public, protected, and default. However, the abstract methods in interfaces can only be public, and the default type is public abstract.
5. the abstract class can contain static methods. The interface cannot contain static methods.
6. the abstract class and interface can contain static member variables. The access type of static member variables in the abstract class can be any, but the variables defined in the interface can only be of the public static type, the default value is public static.
7,A class can implement multiple interfaces, but can inherit only one abstract class.
The difference between the two in terms of application:
Interfaces play a role in the system framework design method, mainly defining communication between modules. abstract classes play a role in code implementation and can be reused.
From: http://azrael6619.iteye.com/blog/618882