Difference Between Interfaces and Abstract Classes
Both, interfaces and abstract classes are used to achieve abstraction in java. Still, there are significant differences between the two. Let’s see them
Interface | Abstract Class |
---|---|
The main purpose of interfaces is to achieve 100% abstraction. | The main purpose of abstract classes is to achieve partial abstraction. |
We cannot create objects of an interface. | We cannot create objects of an abstract class also. |
Interface cannot have variables. However, they can have constants. | Abstract classes can have both, variables as well as constants. |
Interfaces can only have abstract methods. However, since java 8 interfaces can have default and static methods too. | Abstract classes can have a combination of any number (including 0) of abstract and non abstract methods. |
Interfaces cannot have private methods and private constants. | Abstract classes can have private methods and data members. |