Programming Code Examples

How data abstraction is done in C++ Programming2 min read

A class which contains at least one pure virtual functions is called an abstract class. Since abstract classes is incomplete, another class should derive it and provide definition for the pure virtual function in the abstract class.

Following are the features of abstract classes:

  • Abstract class must contain at least one pure virtual functions.
  • Objects cannot be created for abstract classes. But pointer can be created.
  • Classes inheriting abstract classes must provide definitions for all pure virtual function in the abstract class. Otherwise, the sub class also becomes abstract classes.
  • Abstract classes can have non-virtual functions and data member.

Following are the uses of an abstract class:

  • An abstract class provides a commons standard interface for all the sub classes.
  • Abstract classes allow new features to be easily added to an existing applications.

Following program demonstrate pure virtual function, late binding and an abstract classes:

Output for the above program is as follows:

Take your time to comment on this article.

Add comment