Untitled Document

Subscribe here to get updates on new Videos

 

9. Difference between Interface and Absract Class ?

 

 

 

previous homenext


Interface
Abstract class
1. If we don’t know anything about implementation just we have requirement specification then we should go for interface. 1. 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. 2. Every method present in Abstract class need not be public and Abstract. In addition to abstract methods we can take concrete methods also.
3. We cant declare interface method with the following modifiers.

Public ---> private, protected,

Abstract ---> final, static, synchronized, native, strictfp

3. There are no restructions on Abstract class method modifiers.
4. Every variable present inside interface is always public, static and final whether we are declaring or not. 4. The variables present inside Abstract class need not be public static and final.
5. We cant declare interface variables with the following modifiers.
private, protected, transient, volatile.

5. There are no restrictions on Abstract class variable modifiers .
6. For Interface variables compulsory we should perform initialization at the time of declaration otherwise we will get compile time error. 6. For Abstract class variables it is not required to perform initialization at the time of declaration.
7. Inside interface we cant declare instance and static blocks. otherwise we will get compile time error. 7. Inside Abstract class we can declare instance and static blocks.
8. Inside interface we cant declare constructors . 8. Inside Abstract class we can declare constructor , which will be executed at the time of child object creation.