Difference between Abstract Class and Interface
Sr.No | Interface | Abstract Class |
1. | When we don’t know anything about implementation just we have requirement specification then we should go for interface concept. | When we are talking about implementation but not completely (Partially) then we should go for Abstract class concept. |
2. | Inside interface, every method is public whether we are declaring or not. Hence interface is considered as pure 100% Abstract class. | In the case of an abstract class, every method present in abstract class need not be public. We can have an abstract method as well as a fully concrete method. |
3. |
We cant declare an interface with the following modifiers. public -->private, protected Abstract--> final, static, synchronized, native. |
There are no such restrictions on Abstract class method modifiers. |
4. |
We cant declare interface variables with the following modifiers. Private, protected, transient, volatile. |
There are no such restrictions on Abstract class Variable modifiers. |
5. | Every variable in an interface is public static final, by default. Whether we are declaring or not. | We can declare variable in abstract class as per requirements. |
6. | For interface variables, it is compulsory we should perform initialization at the time of declaration, if we don’t we will get compile time error. | For abstract class variables, perform initialization at the time of declaration, is not required. |
7. | Inside interface declaring instance and static blocks are not allowed. We will get a compile-time error if we try to do so. | Inside the abstract class, we can declare instance and static blocks as well. |
8. | An Interface cannot have constructor declarations. | In the case of an abstract class, we can have constructor, which will be executed at the time of child object creation. |