Thursday, 24 December 2015

Differences between interface and abstract class


Sl No
Interface
Abstract Class
1.
If we don’t know anything about implementation, just we have requirement specification then we should go for interface.
If we are talking about implementation but not completely (partial implementation) then we should go for abstract class.
2
Inside interface every method is always public and abstract whether we are declaring or not. Hence Interface is also considered as 100% pure abstract class.
Every methods present in abstract class need not be public and abstract. In addition to abstract methods we can take concrete methods also.
3
We can’t declare interface methods with the following modifiers:
publicàprivate, protected
Abstractàfinal, static, synchronized, native, strictfp
There are no restrictions on Abstract class method modifiers.
4
Every variables present inside interface is always public, static, and final whether we are declaring or not.
The variables present inside abstract class need not public, static and final
5
We can’t declare interface variables with the following modifiers:
private, protected, transient, volatile
There are no restrictions on Abstract class variables modifiers.
6
For interface variables compulsory we should perform initialization at the time of declaration otherwise we will get compile time error.
For abstract class variables it is not required to perform initialization at the time of declaration.
7
Inside interface we can’t declare instance and static blocks. Otherwise we will get compile time error.
Inside abstract class we can declare instance and static blocks.
8
Inside interface we can’t declare constructors.
Inside abstract class we can declare constructors, which will be created at the time of child object creation.
If you really like the post, please comment, share and do like me on Facebook.


Thanks and Regards,
Susanto Paul