Difference Between Interface and Abstract Class

  • Interface methods are implicitly abstract and don't have implementations. A Java abstract class may have instance methods that implements a default behavior. It means that interface is a pure abstract class which have no instance methods at all.
  • Interface variable are by default final. An  abstract class may contain non-final variables.
  • Interface methods and variables are public by default. A Java abstract class can have the usual flavors of class members like private, protected, etc..

  • Interface in java should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends” just like other classes.
  • Interface can extend another interface only and it cannot cannot extend or implement a class, an abstract class can extend another Java class and can implement multiple Java interfaces.
  • A Java class can implement multiple interfaces but it can extend only one abstract class.
  • Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.
  • In comparison with java abstract classes, java interfaces are slow as it requires extra indirection.
  • Interface facilitate programer to achieve multiple inheritance while abstract class don't provide multiple inheritance.

1 comment:

  1. thanks very nice. Today I came to know the exact difference between abstract class and interface.