Abstract Class and Interface Class

What is an Abstract Class?

A class that cannot be instantiated is called an abstract class. An abstract class is only to be sub-classed. It only allows other classes to inherit from it but cannot be instantiated.

What is an Interface?

An interface is an entity that is defined by the word Interface. It is not a class. It has no implementation; it only has the definition of the methods without the body. It is used to define hierarchies for all subclasses and it defines specific set of methods and their arguments.


The main difference between them is that a class can implement more than one interface but can only inherit from one abstract class.


Attachments

  • Abstract Vs Interface Class (27788-20856-Feature.doc)
  • Comments

    Author: Parvathi S02 May 2009 Member Level: Silver   Points : 2

    An abstract class should necessarily be defined by the derived class.
    If the derived class is unable to give definition to the function defined in the abstract class then that class should also be made as abstract.
    But Finally, the last derived class should give the definition to the functions defined in the abstract class

    Author: Deepika Haridas09 Jun 2009 Member Level: Gold   Points : 1

    Hi,

    Good point added.

    Keep contributing..

    Thanks
    Regards,
    Deepika

    Author: John Thomas13 Jun 2009 Member Level: Silver   Points : 2

    An abstract class can contain an interface plus implementations. An abstract class can be extended by adding new nonabstract methods with default implementations.

    An interface cannot be modified without breaking its contract with the classes which implement it. Once an interface has been shipped, its member set is permanently fixed. An API based on interfaces can only be extended by adding new interfaces.

    Thus, abstract class simplifies versioning.

    Author: Deepika Haridas28 Feb 2010 Member Level: Gold   Points : 1

    Hello John,

    Good points!!

    --
    Thanks & Regards,
    Deepika



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: