Wednesday 17 September 2014

Expert - Difference between Interface and Absract Class

Difference between Interface and Absract Class
Interface

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

No comments:

Post a Comment