An abstract class is a class that cannot be instantiated, but can be subclassed. |
An interface is a collection of abstract methods that can be implemented by a class. |
An abstract class can have both abstract and non-abstract methods. |
An interface can only have abstract methods. |
An abstract class can have instance variables. |
An interface cannot have instance variables. |
A subclass can only extend one abstract class. |
A class can implement multiple interfaces. |
An abstract class can provide default implementation for some of its methods. |
An interface cannot provide default implementation for its methods until Java 8. |
Abstract classes are generally used for defining base classes in a class hierarchy. |
Interfaces are generally used for defining contracts that classes can implement. |
0 Comments