Tutorial-8_polymorphism
Tutorial-8_polymorphism
Q1 What is Polymorphism in C++? How many types of polymorphism? Explain with the help of
suitable example.
class student
{
public: int marks;
void disp()
{
cout<<”its base class”;
}
};
class topper: public student
{
public: void disp()
{
cout<<”Its derived class”;
}
};
int main()
{
student s;
topper t;
s.disp();
t.disp();
}
class education
{
char name[10];
public:
void disp()
{
cout<<”Its education system”;
}
};
class school: public education
{
public:
void disp()
{
cout<<”Its school education system”;
}
};
int main()
{
school s;
s.disp();
}
#include <iostream>
using namespace std;
class Base
{
public:
~Base() {cout<< "Base Destructor"; }
};
class Derived:public Base
{
public:
~Derived() { cout<< "Derived Destructor"; }
};
int main()
{
Base* b = new Derived;
delete b;
return 0;
}