Abstract Class Example in C++


By definition, an abstract class in C++ is a class that has at least one pure virtual function (i.e., a function that has no definition). The classes inheriting the abstract class must provide a definition for the pure virtual function; otherwise, the subclass would become an abstract class itself.

Example Program:

Here is the simple program runtime polymorphism in C++.

Source Code

//Class having pure virtual function then this class is called as Abstract Class.
using namespace std;
class Base
    void fun1(){
    cout<<"Base Fun1:";
    virtual void fun2()=0;
class Derived : public Base
    void fun2(){
     cout<<"Derived Fun2:";
int main()
    Base *p=new Derived();
    return 0;
To download raw file Click Here


Derived Fun2:

Basic Programs

Flow Control

IF Statement Examples

Switch Case

Goto Statement

Break and Continue

While Loop

Do While Loop

For Loop

Friend Function in C++

String Examples

Array Examples

Structure Examples

Structure & Pointer Examples

Structure & Functions Examples

Enumeration Examples

Template Examples


Inheritance Examples

Hierarchical Inheritance

Hybrid Inheritance

Multilevel Inheritance

Multiple Inheritance

Single Level Inheritance

Class and Objects

Constructor Example

Destructor Example

Operator Overloading Example

Operator and Function Example

List of Programs

Pointer Examples

Memory Management Examples

Pointers and Arrays

Virtual Function Examples

Learn All in Tamil © Designed & Developed By Tutor Joes