Difference between Interface and Absract Class
Interface
- if we don't know anything about implementation just we have requirement specification than we should go fr interface
- inside interface every method is always public and abstract whether we are declaring or not. hence is also consider as
100% pure abstract class - We aren't declare interface method with the following modifiers
public-> private, protect
Abstract- final, static, synchronized, native,strict - Every variable present inside interface is always public, static and final whether we are declarin or not
- We can't declare interface variable with the following modifiers
private, protected, transient and volatile - For interface variable compulsory we should perform initialization at the time of declaration otherwise we will get
compile time error - inside interface we can't declare instance and static blocks otherwise we will et complie time error
- inside interface we can't declare constructors
Abstract
- if we talking about implementation but not completely (partial implementation)
than we should go for abstract class - every method present in abstract class need not be public and abstract
in addition to abstract method we can take concrete method also - there are no restrictions on abstract class method modifiers
- The variable present inside abstract class need not be public static and final
- There are no res traction on abstract class variable modifier
- For abstract class variable it is not require to perform initialization at the time of declaration
- inside abstract class we can declare instance and static blocks.
- inside abstract class we can declare contractor, which will be executed at the time of child object creation
No comments:
Post a Comment