In many interviews you can face this basic question -What is the difference between the Interfaces and Abstract class and when we can use from both of them.
Interface | Abstract Class |
If we don't know any thing about implementation just we have requirement specification then we should with Interface concept. | If we are talking for Implementation not completely Partially implementation then we should go for Abstract Class. |
Inside Interface every method is always Public and Abstract whether we are not declaring or not. Hence Interface is also considered as 100% pure abstract class. | Every Method in Abstract class need not be public and Abstract. In addition to abstract methods we can take concrete methods also. |
We cannot declare interface method with the following modifiers. Private ,Protected final,static,synchronized,native and strictfp | There are no restrictions on Abstract class method modifiers. |
Every variable present in interface is always Public , static and Final whether we are declaring or not. | The variables present inside the Abstract class need not to be public,static and final. |
We cannot create object of Interface and because of that we cannot declare interface variable with the following modifiers: private,protected,transient,volatile | There are no restrictions on Abstract class variable modifiers. |
For Interface variable compulsory we should perform initialization at the time of declaration otherwise we will get the compile time error. | For Abstract class variable it is not required to perform initialization at the time of declaration. |
In Interface Constuctor is not applicable | We can declare the Constructor in Abstract Class |
No comments:
Post a Comment