Polymorphism

Polymorphism

Polymorphism
Ganesh
Tuesday 7 March 2017

Polymorphism-

Poly means many (เค•เคˆ เคธाเคฐे) เคนोเคคा เคนै, เคฏเคน OOPS (object-oriented programmingเค•ा เคเค• concept เคนै เคœिเคธเคฎें เค•िเคธी function เคฏा operator เค•ो เค•เคˆ เคคเคฐीเค•ों เคธे เคเค• เคนी name เค•े เคธाเคฅ access เค•िเคฏा เคœा เคธเค•เคคा เคนै ।
Polymorphism are two types.


Compile time Polymorphism-
Program เค•ो compile เค•เคฐเคคे time เคเค• เคนी name เค•े function เค•ी เค…เคฒเค— definition compile เค•เคฐ เคฆी เคœाเคคी เคนै।
Compile time polymorphism เคฆो เคช्เคฐเค•ाเคฐ เค•ा เคนोเคคा เคนै।

(i) Function Overloading- เคเค• เคนी name เค•े function เคชเคฐंเคคु เค…เคฒเค— เค…เคฒเค— parameter use เคนो เคคो function overloading เค•เคนเคฒाเคคी เคนै।

Example- 
void area (int a, int b)
void area (int c)
void area (int d, int e, int f)
int area (int a)
{
return (a*a);
}
int area (int b, int c)
{
return (b*c);
}
Cout<<area(5);      
// output=25(area of square)
Cout<<area(5,10);
// output=50(area of rectangle)

(ii) Operator Overloading- เคเค• single operator เค•ो เคฆो เคฏा เคฆो เคธे เค…เคงिเค• เค•ाเคฐ्เคฏो เค•े เคฒिเค เคช्เคฐเคฏुเค•्เคค เค•िเคฏा เคœाเคฏे เคคो operator overloading เค•เคนเคฒाเคคी เคนै।
Example-
5+2=7
เค‡เคธเคฎें '+' operator เคฆ्เคตाเคฐा addition เค•िเคฏा เค—เคฏा เคนै เคเค• new (diffrent) output เคช्เคฐाเคช्เคค เคนुเค†।

ganesh+gururani=ganeshgururani
เค‡เคธ example เคฎें เค‰เคธी '+' operator เค•ो เคฆो string เค•ो catenate(add) เค•เคฐเคจे เค•े เคฒिเค เคช्เคฐเคฏोเค— เค•िเคฏा เค—เคฏा เคนै เค‡เคธเคธे เคœो output เคช्เคฐाเคช्เคค เคนुเค† เคนै เคตเคน input เคธे เคฎिเคฒเคคा เคœुเคฒเคคा (เคธเคฎाเคจ) เคนै।

Run Time Polymorphism- Program เค•े run เคนोเคจे เคชเคฐ เคเค• เคนी name เค•े เคฆो เคฏा เคฆो เคธे เค…เคงिเค• function เคฎें เคธे เค•िเคธे execute เคนोเคจा เคนै เคฏเคน decide เค•िเคฏा เคœाเคฏे เคคो เคตเคน run time เคนै।
★Run time polymorphism เค•ो virtual function เค•े เคœเคฐिเคฏे เคช्เคฐाเคช्เคค เค•िเคฏा เคœा เคธเค•เคคा เคนै।