The difference between abstract class and interface is frequently asked in interviews.
Characteristics of abstract class
1.Both abstract class and abstract method needs to be declared with 「abstract」
2.Using「new」to generate object on abstract class is not allowed.
3.Abstract class needs declaration but not necessary to be implemented.
4.The derived class needs to implement the abstract method in the base class.
Otherwise it's merely another abstract class.
abstract
Characteristics of interface
1.No constructor in the interface.
2.All the data members need to be initiated
3.The parameters need to be declared as public and final,or static.
4.Abstract methods need to be public or abstract.
Note to avoid confusion 1. Class in java can only inherit one base class. (While in C++, multi-inheritance of class is supported but not recommended) 2. Interface can do multi-inheritance on interfaces. 3. Class can implements multiple interfaces. When to use abstract class or interface ?It's been widely discussed for long time about when to user abstract class or interface.As for me, I will intend to use abstract class and inheritance to describe the characteristic of the class.And I will use interface to define functions that can represent the capability or behavior of it. That's my principle,depending on the project,developers can have their own style or principles to use abstract class and interface flexibly.