Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Sunday, December 14, 2008

Differences between interface and abstract class

The interfaces and abstract classes, both can't be instantiated. While an abstract class contains both implemented and non-implemented methods, an interface contains only abstract methods.

INTERFACE
  • An interface is pure contract
  • Interface must be public
  • It may be left unused after declaration
  • When used, Implementing class must override all methods provided by that interface.
  • It contains only unimplemented methods and no function definitions
  • Variable must be abstract and final
  • Methods take abstract as default.
  • A single class can implement multiple interfaces.
  • Interface properties are included with "implements" key word

ABSTRACT CLASS
  • Abstract class must contain at least one abstract method
  • It can contain function body
  • It contains both implented and unimplemented method.
  • It allows both abstract and non abstract methods.
  •  It must be used if declared, otherwise compiler gives an error.
  • It may be public or protected.
  • Only one class can extend abstract class.
  • Abstract properties are included with extends keyword.