Polymorphism is a function call which can refer to the function which differ according to the type of object to be passed into the function that called it. In C + + can be reached by using virtual functions.
Virtual function is a function that is declared as virtual in class parent and redefined in a derived class or more. To declare a virtual function in the parent class, you simply adding the virtual keyword.
Virtual function is a function that is declared as virtual in class parent and redefined in a derived class or more. To declare a virtual function in the parent class, you simply adding the virtual keyword.
see the code :
#include <iostream.h> using namespace std; int size(int x); int size(int a, int b); int main(){ cout << "Size of a square with side 5: " << size(5); cout << '\n'; cout << "Size of rectangle of with sides 5,4: " << size(5,4) << endl; return 0; } int size(int x){ return (x*x); } int size(int a, int b){ return (a*b); }
0 comments on Polymorphism sample In C++ Language :
Post a Comment and Don't Spam!
Dont Spam please