Interface | Abstract Class |
---|---|
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 |
Inside Interface every method is always public and abstract, whether we are declaring or not. Hence interface is also considered as 100% |
Every method present in Abstract class need not be public and abstract. In addition to abstract methods we can take concrete method also |
Every variable present inside interface is always public, static and final whether we are declaring or not | The variable present inside Abstract class need not be public, static and final |
We can't declare interface variables with the modifiers : private, protected, transient and volatile | There are no restrictions on Abstract class variable modifiers |
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 |
Inside interface we can't declare instance and static block. Otherwise we will get compile time error. | Inide Abstract class we can declare instance and static block |
Inside interface we can't declare constructors. | Inside Abstract class we can declare constructor, which will be executed at the time of child objectcreation. |
We implements interface. | We extends abstract class |
Tuesday, March 29, 2016
Difference : Interface and Abstract class
This is most common question in the interview room. Many of interviewee are confused or find them-self trapped while answering this question. Following are the basic difference between the abstract and interface
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment