What are the differences between abstract class and interface?

Solution:

Abstract class Interface
An abstract class can have a method body (non-abstract methods). The interface has only abstract methods.
An abstract class can have instance variables. An interface cannot have instance variables.
An abstract class can have the constructor. The interface cannot have the constructor.
An abstract class can have static methods. The interface cannot have static methods.
You can extend one abstract class. You can implement multiple interfaces.
The abstract classcan provide the implementation of the interface . The Interfacecan't provide the implementation of the abstract class .
Theabstract keyword is used to declare an abstract class. Theinterface keyword is used to declare an interface.
Anabstract class can extend another Java class and implement multiple Java interfaces. Aninterface can extend another Java interface only.
Anabstract class can be extended using keyword extends Aninterface class can be implemented using keyword implements
A Java** abstract class** can have class members like private, protected, etc. Members of a Java interface are public by default.
Example:
public abstract class Shape{
public abstract void draw();
}


Example:
public interface Drawable{
void draw();
}


0 answers