You are on page 1of 28
Poly moxphignn = = » Pelymorphiam ri means the. “ability. te take more Han me Form, ee *) Polymerphiem is one ef the importont Feahures of OOP. £ one Name , multiple Forms” Polymorphism means N) an eperation may exhibit different behanours in different _intancer. The behaviour depends upon the typa eof data usted in the operation. for example considex the operation oF __addition, fer two numbers, the’ eperation ill generate .- a_sum, IP the operands are Strings, then the eperttion - Weould “produce. a third String by cenatenahon. ® Trove are “two types of palynerphigm — 0) conpile!— He» potymerphiem a) Ran, ime Polyrmarphie npile’- Hime pel higm Can be achiewed using? Function overloading and opeyatoy overtvading’, Virtual win-tme _polymorphisny is ae ua Seiad ot mun re See The Tunis be wel. ‘Scanned with CamScanner Ee eareanip ‘S included amie. b> ne int mud (int a, int 2); * Wyeid_ mul i, void mud Cint x int = tu) (int x, int y, int 2) eee i _ ee OF ie mudd double & deub\c double Mul( deube wm, doable q); Ts int maine) Veid_ maine) _ ukemul(t eendt, oT 2,8 he wd (9-5 ‘11 endl ‘Scanned with CamScanner ake roul (int a, int b) pt a a ehuen (eb) SS int %, int yy int x) a os Sai = ink mul (_ eee ze Tehuyn (ERY ex) . Ie 7 Avuble ul ( double p , double 0 _ Behe Cpaqys = — —= - 5) Jn above example the function lokstoid maine mulC) har Hee vewtion. a0 d i. upon _types of orguments ahd number ent pa in function eal] the ii at oy, geendl, __wompiler selech the appropriate. funchon | ‘Scanned with CamScanner E- nchion, pvewloadi Jas the Facility ility of Pel pvewto e can define ma Runchon uit} Same enks are diverent ~ : eee the. number and type ‘b oF the ayguments bub not on the Tunetion type ot. bility te take moe 4h See St Pelynaphien. wa ‘we the some a a ‘Scanned with CamScanner sum si “$2, 89; os aie “Bh addition Cn, 10) __ St addition ¢ 4-0, 428, a = 28 addition BB addin is: 5-3 additin is: 12 ll fxanple2) Progra m to enplain the eoncor? with one # include —__tinary operators while a member Function has ne Sxpuments For unary i “OPerabrs | 4 3 a z ‘Scanned with CamScanner "tl cet “Fun cHons can be er’ pees wn: spperakers | b ne Se o: ai aa wr binary mabors ng, oles ' xopy ov x op woud be inept oe operator op ¢x) »)._fer. member functon x op y would be tensed ag 4 ___Reopewator opty) 5) For Friend Function x op “would be interprebed an 4 operator opty) an ee — ae — hearing to the operands wequived_Fer_eperabion _ al) operotors ave divide ints three categencs tc - | el | +2 “binary | a ter nary 7 , require only one dpercind to pomfer operat ; Sr ‘Scanned with CamScanner - be applies! The unary minus operator oan DE OF

a class _ space _ a eee ea —___pulic: a void getdate Cint a, int b, int ¢) La; ‘Scanned with CamScanner . e) - a played} Hach ns dh dhelnsi J. veh er ehenelar 6) funallan The Ainctian operator <6) (mker ne Caputeint Ah Paneer the it dada menbard’ er Whe obtel: S. sin tla Pureton (a a member Punetin of Me tame clit, Te can cliveadip acces Me menher of dhe objet which eh veel overleading’ unavy minut operator using” felened Purabtan « WinchudeZ fostream: h» # included sonia: n> pinched class space, Sa int *y,e; ae a gaa TT a, We b, Yak ed 2 j meas os ‘Scanned with CamScanner COuheeee are, callin s- earlate: . Fs ‘Scanned with CamScanner ding’ binar = __Tedulras_ hod operords 4o_yorforn. “operabion, _--_ —Felnhg_Fregren shows hro_bieery + opembor_is__ —— TF include 2 iostrenm « hp include £sbvingsh Class, concat ah { har str (uel; ‘Scanned with CamScanner ‘Scanned with CamScanner ~ Hinelude 2 Jeatream. > _ Findudec Biing: n> “das concat . 4 ° Cheur BhrCt0y oo a ub Tic ; : a void tnpukey i contrveh : Concatey Course Entog er the ashing a a Ae Ciin>> str; . Ww + Se _ Vere) Concar opowator + Caan cab x) 5 ‘Scanned with CamScanner fencat er, co. cs: : @ ae y “Inputed; : Be tout 2e6inin stein boFere concakenalion® age ee te y ‘Scanned with CamScanner —tusteading —Vinany operat using’ Friend Funsien- inolu, oh los —tiloelude Cabingshy Claws concab ee UL char stylue: publics 7 Void inpubey - i: coub2e*in enter a thing: eins atr: et 3 a a void dlisplayey qoulee*\p ehing 1s: ™ zesty, A ‘Scanned with CamScanner Conca ct cry : tobe 3 an thilapabt fe Crs Inpub ers Lt — - toubectetnin Giving before calenahion : \n%? + Chealisplay ey: i reenkct pt dog ater toncalenalin fia? SOULE nln shin? ePterconcsenahion s\nOty COUdL LEE n\n Bhan Operahor 4+ Cc) ers aS Rules Por _overlnadin Operators - e enh existing op coordleg can be evesloade). New operate: cannot -be create. 2) The evertoaded operator soust have at least. one operane! thed is oF wey defined type. 8) We cannot change: the basic rmeaningy of an Operator. that is we cannot edefine the Plat (+) operator to Substyack one value Prom the cher. 4) puerloaded operators Pollo: the _syntar tales oF the es otors that connst “be — ‘Scanned with CamScanner @\3 6) nowy oporaors overloaded by moang of 4 rmembor function, takes no ents and welurn ne values Sub thate Unary oporater OUerfraded by Means oF a frond funch take one weferonce ene - 9 Binary oparators overloaded Arough a member Punckon “Fake one. argument and these which cre ovestoa Haugh a Friend fFunehion take two ents §) when using, bin spoxators Overloaded though 4 rrembor Funelisn, the \eht-hand eperand snugt be Gn object of the ‘elevant class - : _9) Binary axthmatc. operators such as +, -) * | musk welurn a value. They mutt not attempt ts Change they ents. ts) we, cannot use Friend Funehons te overtoad certain : => Claas member acces operater . : a ‘Scanned with CamScanner he You aHampe ter wedatine. virtual Funclon 4, He FaneHon will ba considered: vovédloader by eH. nd fds virtua) nekre wil be Test - # indude Lileskrtamipee ce a clay Base 3 gee L ____ Publis” ‘Scanned with CamScanner . | 1) a) He) Rate ms : Devivor ) Pidliptay «> D: ALY agal ot ¢ Z ‘Scanned with CamScanner “tnt edger gies el at dranic Windy ng saippalli im ) Sarees a Situatton oceums where Function name. ond Prtbetype is same in beth the base clay and in the _ demi clos. _ 2) _tompiler does not new whak to do , which Sundion +0 , Call, En this case arpwopwiate member FuneHm fo scbech — 8 He Hime ot _wunning the program. His ie bina a3” Run. Hme pore phi em» i a 4) the win-time polpmerphiem is achieved twingy victy Function. The Functon ts be used js Selected ab wean Hine Fi wun-time when daw sbjeds are under consi dexakion , the appropwiate Version of the Function is called © This is called the dynamic bindin er late birding” Means that binding of object and Funct call is dene oF uy Hime ¥)_n Run-time polymerphien tes the eelestion of on ——Stempriate Runction is dene dynamically at sun Hme 8) To_impement dynamic binchin, the ohfeok pornters ond vital Fundions are uied. a tiehual Fundions are wed a Virtual funchion — i = a ) viztial function iso Member Function that is declared sein a bate cla and wadefined within a demved claw. ; Bvbey eae he eae fanaa dare kas the _bate and der chest Whe _fundton In bate cla as ‘Scanned with CamScanner oo =_felnter 42 pane ‘pede Coubee*\n display bases”. s __Vithia) void show) $ coub coin chew base; derived : public base ‘Scanned with CamScanner Coub2c\y pty points te baie® in) ———_—__ Sees shbs > ptr > diaplayer: tealls base version ec ptr ~> shew er; oe bate version 48\n pky_peints to derived tn”; s ‘ ptr= Qd > : = + => dlisplaye): Healls base Version pir -> shows); N calls s “derived version lehey > ee ‘Scanned with CamScanner in Funder tn must ba Mimbo oF Gere laws, are actemad by ‘using objet poinkang rf ion can bea Friend Of another cla f Function 10a tose clas must be Aeheed , ever it may nei be usad. . atolypes BF the base clays yeasion Of 1 yyducl tutehar oll the derived Claas Jerions must be same. TF dun ons “With he same have’ difernk a unont tisk, at 1 O4 eveHtoaded funchans and Viwhual FuneHap is ignored 7 hawe. vinhval conghwushars cannot be virtual, but destwuchar fiancbr can @ sshile a bate printer con point fo the objeer of dewul ae ee Pointer of donived che can not use BB rine he ot jeeb of bate claw. - whtal Runetion - ) Pure Witty Function js a Vietved funckiony -thab. has 10 deFinition jam) wrtbin the baue cox. ea fort) to declare. pure Virtual Funckeny is 3 © Virtual! aid displ oe en @ visual funchen ic made pure , any dosive é oust provide ifs oudn) defini on). 2 the derived ‘Scanned with CamScanner —_vishual veld “shaoU=0; Tl gue ofeiel Pandton. void shew) ; Coutce™ addition is =" debe class multiplication’: ~ public «| ‘Scanned with CamScanner ‘Pindude Zectream.hs include ¢ tonioshy ‘Scanned with CamScanner void getdataey) 4 eS eee £° cou) Ze" Enter J Rt —- ___Uns) dob; void crreacy Lab: - avea of vedangie M26 Or; Void malnc = Shape brian p= .__-_'= te - P->areary octangle Petty Y- accept ¢ ‘Scanned with CamScanner

You might also like