What is Difference between Interface and Abstract Class
Interface |
Abstract Class |
If we talking about implementation but not completely(partial implementation) then we should go for Abstract class (abstract methods + non-abstract methods+ constructors , blocks, variables..etc) |
If we don't know anything about the implementation just we have requirement specification then we should go for interface (abstract methods (In Java8 Default, static methods too) |
Inside interface every method is always public and abstract wheather we declaring or not. Hence interface is also considered as 100% pure Abstract class |
Every method present in abstract class need not be public and abstract. In addition to abstract methods we can take concrete method also |
We can't declare interface method with the following modifiers Public->private ,protected |
There is no restriction on abstract class method modifier |
Every variable present inside interface is always public , static and final whether we declaring or not |
The variable present inside abstract class need not be public static and final |
We can't declare interface variable with following modifiers private , protected,transient,volatile |
These are no restriction on abstract class variable modifiers |
For Interface variable compulsory we should perform initialization at the time of declaration otherwise we will get compile time error |
Not required to perform initialization at the time of declaration |
Inside interface we can't declare instance and static block otherwise we will get compile time error |
Inside abstract class we can declare instance and static block |
No Comments Yet!!