Let’s learn difference between abstract class and interface in java.
Difference between abstract class and interface in java
Here’s the difference between abstract class and interface.
Abstract class | Interface |
If we know method implementation, but partial implementation then use abstract class. | If we know do not know method implementation then use interface. |
Each method in abstract class need not be public and abstract. | In interface each and every method is always public and abstract by default. Hence 100% abstract class. |
Abstract class do not support multiple inheritance. | Interface support multiple inheritance in java. |
There are no restrictions on abstract class access modifiers. | cannot declare interface methods with private, protected access modifiers. |
Variables in abstract class need not be public, static and final. | every variable in interface is public static and final by default. |
There is no restriction abstract class variables modifiers. | cannot declare interface variables with private, protected, transient, volatile access modifiers. |
Not required to initialize at the time of declaration. | interface variables should be initialized at the time of declaration. Else we get compile time error. |
we can declare static and instance block. | we cannot declare instance and static blocks. |
we can declare constructors. | we cannot declare constructors. |
Also read – java overview