Polymorphism Program
Polymorphism Program
#include <iostream>
class Geeks
public:
void func(int x)
void func(double x)
cout << "value of x and y is " << x << ", " << y << endl;
};
int main() {
Geeks obj1;
obj1.func(7);
obj1.func(9.132);
obj1.func(85,64);
return 0;
value of x is 7
value of x is 9.132
#include <iostream>
class Complex {
private:
public:
Complex res;
return res;
void print() { cout << real << " + i" << imag << endl; }
};
int main()
c3.print();
}
// C++ program for function overriding
#include <iostream>
class base
public:
void show ()
};
public:
void show ()
};
//main function
int main()
{
base *bptr;
derived d;
bptr = &d;
bptr->print();
bptr->show();
return 0;
}
// CPP program to illustrate // concept of Virtual Functions
#include <iostream>
class base {
public:
void show()
};
public:
void print()
void show()
{
cout << "show derived class" << endl;
};
int main()
base* bptr;
derived d;
bptr = &d;
bptr->print();
bptr->show();