Read More about : Interface in Java
Read More about : Abstract Class in Java
Similarities between Interface and Abstract Class:-
- We can’t create object for both.
- All the abstract methods must be overridden by subclass.
- Don’t have default constructor.
- By using both we can go for dynamic polymorphism.
- Both can contain static and final variable.
- Both inherited from common domain of itself using extends keyword.
- Both provide static method implementation.
Difference between Interface and Abstract Class:-
|Abstract class can have abstract and non-abstract method||Interface can only have abstract method.Since java 8 ,it can have default and static method|
|Abstract class does not support mutiple inheritance||Interface supports multiple inheritance|
|Abstract class can have final ,non-final ,static and non-static variable.||Interface has only static and final variable.|
|Abstract class can provide the implementation of interface.||Interface can’t provide the implementation of abstract class.|
|An abstract class can extend another java class and implement multiple java interfaces.||Interface can extend another java interface only.|
|It can have class members like private ,protected ,etc.||Members are public by default.|
|Abstract class can not be instantiated but can be invoked||Interface can not be instantiated or invoked|
|Abstract class has parametrised and non-parametrised constructor |
but don’t have default constructor
|Interface does not support the concept of constructor|
Follow Java tag for more related article to Java Programming Language.