What is the difference between abstract class and interface ?

 

Abstract class Interface
1) Abstract class can have both abstract and non-abstract methods. 1)Interface can have only abstract methods. Since Java 8, it can have default and static methods also.
2) An abstract class can extend only one class or one abstract class at a time that means Abstract class doesn’t support multiple inheritance. 2)An interface can extend any number of interfaces at a time that means Interface supports multiple inheritance.
3) Abstract class can have final, non-final, static and non-static variables. 3)Interface has only static and final variables.
4) Abstract class can provide the implementation of interface. 4)Interface can’t provide the implementation of abstract class.
5) The abstract keyword is used to declare abstract class. 5)The interface keyword is used to declare interface.
6)An abstract class can have protected and public abstract methods 6)An interface can have only have public abstract methods.
7) An abstract class can be extended using keyword “extends”. 7)An interface class can be implemented using keyword “implements”.
8) A Java abstract class can have class members like private, protected, etc. 8)Members of a Java interface are public by default.

Note:-Disadvantage with an interface is, if you want to add a new method in interface, then you must be implement in all of the classes which implement that interface. But in the case of an abstract class, the method(non-abstract method) can be simply implemented in the abstract class and the same method can be called by its subclass.

One thought on “What is the difference between abstract class and interface ?

Leave a comment