Difference Between Abstract class and Interface.
| Abstract Class | Interface |
|---|---|
| 1. If we are talking about implementation but not completely (partially implementation) then go for abstract class. | 1. If we does know anything about the implementation then we should go for the interface. |
| 2. Every method present in abstract class need not be abstract ,it can be not abstract also. | 2. Every method present inside interface is by default abstract. |
| 3. Every method present in abstract class need not be public. | 3. Every method present inside interface is by default public. |
| 4. We can use any modifier for the method. | 4. The following modifiers are not allowed for the interface methods: Strictfp , protected , final , native , static , private , synchronized . |
| 5. No restriction for abstract class variables. | 5. Every attribute present inside the interface is by default public , static and final. |
| 6. No restriction for the abstract class variables. | 6. Following modifiers cannot declares for the interface variables Private , protected , transient , volatile . |
| 7. No restriction for the initialization of abstract class variables. | 7. Compulsory initialize the variables whenever declaration. |
| 8. Inside abstract class we can take instance and static block. | 8. Inside interface we cannot take instance and static block. |
| 9. Inside abstract class we can create constructor. | 9. Inside interface we can not create constructor. |
0 comments :
Post a Comment