Tuesday 24 February 2015

Polymorphism in C++

Polymorphism
============

Polymorphism means how to put the same thing can be used
for different purposes.

Polymorphism Can be Achieved in C++ By Two Ways
===============================================

1) Function OverLoading
2) Operator OverLoading

Operator OverLoading
====================

int a=10,b=20,c=0;
c=a+b;

float a1=10.4,b1=20.4,c1=0.0;
c1=a1+b1;


Function OverLoading
=====================

#include<iostream.h>
#inclue<conio.h>
main()
{
clrscr();
cout<<"\n Addition Of Two Integer is :"<<add(12,34);
cout<<"\n Addition Of Two real Number is :"<<add(12.5,34.4);
getch();
}
int add(int a,int b)
{
return a+b;
}
double add(double a,double b)
{
return a+b;
}

No comments:

Post a Comment