[go: up one dir, main page]

0% found this document useful (0 votes)
20 views35 pages

inheritance chapter

The document discusses various types of inheritance in programming, including single, multiple, multilevel, hybrid, and hierarchical inheritance. It provides examples of classes and their relationships, illustrating how derived classes can inherit properties and methods from base classes. Additionally, it includes code snippets demonstrating the implementation of these inheritance types in programming.

Uploaded by

shindenanadu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views35 pages

inheritance chapter

The document discusses various types of inheritance in programming, including single, multiple, multilevel, hybrid, and hierarchical inheritance. It provides examples of classes and their relationships, illustrating how derived classes can inherit properties and methods from base classes. Additionally, it includes code snippets demonstrating the implementation of these inheritance types in programming.

Uploaded by

shindenanadu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 35
: I 239. =rnhewitancé _—_® : : — y prt ‘om | 2. the mechan) eS ngs class from anothey deviving 4 CEP =e — 4° hesitance. tT eases Ss aatted aise ; i . : =the. claes. from Which anothey Glass derive ig Called AS base "clase. wnle *he class which IS aewwe \e called a6 deviNed class, _ Theve ave five *Y pes of Thnevitance . H > v Single inheritance Ne + v vn multiple inhewitance 3) multilevel hesttance 4) Wibvid “Inheritance - Ss) Weranchical Inheritance Le A EE ——lgingle Mhexttance 2-7" TEh the: singlecinherit—|p ——~)aherirance. |ance, ——F gyethee C158 - this Is) Called éingie TJ i 2) |—Multipie—inhrestdnce — 8 7 ex pp WAP Fe ddd wo Nurnbevs using Class Function must accepted te nuimbey Eyer usey and the derived cass onl one class 15 dewived Prom clese— Q [e~ Based class [etass=8 k- devived class } Single ‘phevitance . Such Fhat based Function must add this humbev and dis play the sum, Data | Private protected J asvit Orch public vead CD - sutn _ Public SS er eae include, icskveam> uging namespace Std) class Data ’ It | Protected: : [ine asbs_ public 2 welt ead mins me Courcc’ Emer 2 number"; Ansy-az> b5 ES * ‘ class Sur! pub! ic pata { a | Private + inh Cf puriic : void addc). rh C= OM, f. m+ main () —— void dispiag C) ol |= Sums: z —_ | course” The mig | a Ene f Usi Namespace Std; f ‘Glass © Neniele t = Public * Chay M 5 int 3-01) Public * Noid out input co) Cour ce Enter Mode of coe; ENS mM; ~ Course Enter fuer capaci} 7 CInss PR; 7 Course” entex Hye" cinys om Courge>* Ewey ar eins Sy | cf i | ian CaN. public Nenidle tne 5 ft pubite 2 — | : ee es | Motd -computcy _ APS A Re eS es Th Wie Nold display ¢) cout<<'" distance “xed 5 EF nt main ©) ie ; Vehicle s! S+ Jnpur oy Soe cdrmput CJ; display €); Atehreh 0; s 4 Write a Prvogrsaro +o implement Sige inneritance, From Rotlowing =f accep+ - and display the data. ‘Roy one ‘rable. Clags — Furvnituve. data members + Material ; T Price Class — Table Surface area, data members + height; _ FF include teem = Ben b I int YW ~ say public. : Void’ ourpur C) Class table? public Fuvnituve t : i Public void display ¢) t PCOUNN Gus the Ynatervial price IS”X< price: “wk main 0) to furhiaurce 0 oy inputcd 7 , ee Oo: display ¢) — dekurtn 0} élass uname @/ Employee meme NaviableS * emp aids Name © Class name? €mmp'— info member. Variable: bagic ~ Salavy”. AE Mdlude> names ch class emp ~inka : public “empleyee oe private ean ee yt Sp —H public 1 ' ae To oid output C) 7 cote tne” 3 Cour ed id of employee ="" —_L —— — nt mao employee Cs Ce Void input C)) L veld ovrtpekO ety °* | de | Mulileve! ownheritanee 9 B— PD The tmechaniem of derived ' lags | Gye anethey denived . class’ 1s know as mutilevel— inhewitance ss? i i ey “anethey child: Class hen it When oo baced “Class. ; \s-“dervived ~ mt Child Class hich fuvthes — devived | IS cK hewn aS MmuHbieve) hheryitance | [Base class } — | [ tevived “Class ib : LL Derived class 2: | Fig. multilevel Inhenitance., @acampl 2- _ a Witte a pips impliment inhevitance qe Shown, MH The Figs assume data fy suitable. member funcilen an “accept and display Runctien . customer name Nurnbey Deposi+tey Ace — No balance 7 Bowrewer > _boon—-No Loan ~ Areount —. EZ include 2iosveams using Mamespace Std; Class Customey Porisn yy _ Pretectd Int ph ho} Chay Name C20}; Mig 2 Void ¥ ) Public oid : pact C Coup<< Enicy Name & phene Wurnber ' ons > Name >> ED no} Noid putdata ¢ ye t Courx<" We Rane | << name, Cout<<"" Phone. Number '* int acc Ns } | Boat bal ; Noid Bercy | s = _| YT CourecEnbey ACcouWHty, balance) cinsy Ree-NeSy bal; mys void purl C) eo Cours" Account | ne” lean amme jp [Ne PUTO ue t Oe Course” Joan No ’!, << leah -ho; cout lean Amhoun! "-<é loch ott wwe Moin) a a {je PATI oWEY by Date Poge ] b. gerdaracys : bh. purdaka (yp Se b- ger Os _ [ pura) 4 | b. Geky; = | ibe purty cyy 1 vetuvn 0} je 5 am AE [Wap em jement. inbeviHtance) aS Shown in whe Ry. [_shdent Neq—ho Name a Acatemes Rest year Mayes Second yeay Marks 7 rings} year Marks ope St ns ie ee Sudden rsa — Mgtouk a ‘AsSout = an curvent+ a kK classmate a == Ar inciude Heme} 5 = Voll putdatac) £ Cout<<'' The Feg- he” = << Yeg-no ; Couregd" “Whe Name! << name; ee " class Accademics .: Public Stydend zt Protected Float Pmovky Smark) Vratks; : Noid getc) : _| =z § r wa | HL { Couxe” Entey a marks 1; CINDY RmavksSS Sma SS —PMaviKs 1 | Yold putd C) Lz Cour [ COUTK SY E Mavks!" Se timayRs) = r a | Class “student 2 public Mecademieg Protected 2 Int Pass~ Year | 6 Chay Cun werk Vol d eric ‘ Lone ao : r Cout aii Tnhertance ok wo oN move class “ag Showh iw othe Fig. : 4 A clase can inhewe the a Bs | Lenqes Te We | L r | i 4 =) | H Le r Pig. Multiple inheritance. , a _ Mubipie inheritance alloWS +o a Corb Fearne Several exist | Classes as Shayeting fey deRi _ > Iwhevit+ + Phe “physical sap one petenr cond he Se “of another - ~Taemify the Fypes =F ag “Shown the Pig. below oo — = Glass Warne : [class Name = employee Emp ainion re member vervlable ¢ emp'id | emp-Name ia fr +t - a ete - | ar EMSs name : emp_info | | 7 Ynembene. variable © P 1 Basic savy | classmate, i oy - Vhisie, example of youltiple Mhovitances | AF iheludes ine> emp —name } out! enter id’) ——~T ein >> emp —idy_ TF ource) Enter union id's fea “anys emp member —id 4 4 | course Enter basic Salary" ains> basic — Salary void emp — ino? purdata ¢) t cour<< Employee id edemp—)y cout<<"" Employee Nome’ 2 a = _ __emp= info oby ; _ obj. _ Qetrdarta cy Z - ; 7 = omy ‘ purdata ¢ On classmate. 2) [wap ir “NV cless Bram; Fe ctass's Wbvavy member’ variable + |: ' membey variable, } Supiect name » | seifec —na | aeee ; 7 aa 7: | \ i 4 i | Wen - - le x Sy ‘Class student: member Naviahie. Le : \ Rol} no , name | SF Tnelude Zjostveam y using Namespace Std, clags brarn (ee | Protected = Chay Subject name’ + 3 class Ucia? a ee Pa Sa protected ‘ Tha Accano ‘ ' Sy | Class student? bublic exam } ° Public Morante t wt Roll noy _ Hee Chay Name, Pubic + void getdatac d> Noid _ Putdabac) . Void tudent-2% genata c)_ C Cours! Ente d subject name" ) ON>> Subject - name; Cout<< Enter al Rec —ne"? ciny Accche; Cour<< ** Brter a Ball Neo jr CinSS Aell-ho Cours éntcy a name} SAE Ansys names | Ss 4 Noid student 21 puddata C) = foycjeoy jaer. j++) ae a in cout MCAS, 3 | | 5 \ | FovCicos jens ith) a foc ne fea pxehatt) NGG= 0 - it HODES > VENEERS nd F — ! Brinctude< lostre am included math> using ndmespgce Std nt Mainc) 2 lat Wier, YC) 3, Int Clo or) MPC» NCL] LY Couto bivbey news, and Column Rov Rivst yogtyiae! 5° (ores CMS TNL pz out> emp _ fel 7 Vatcl lis plat) { Ye Louk Employee name" << emp -hame * i i Cout <4 "Emp tel ''<¢ Cp - id? 2 te C4SS_workey > Public employer i Proketeel t float avertime . sala Zoid accept c) Fecubvet fon for-oVer UT mphyee 21 _accogte) ot<2" Enter aver me salary" Cth 22 ove, timo L 3 eich —cligpay 2 — £ employ ee ridisplay-O Coutie overtime sal 1122 xey time Sal; t [ge agate —eelayee £ Prodecteol > float gald:tional_~ allowante; Publiz 2 vopcl accepic) is yapley ee ALI eptt) £ cout using names pate ‘Stel } tr class student 4 froteck df : int wall po: bree k ord ra chay name ? } Dublit > void cetclata C) £ Cout £2 Entey Rell no £ name": Cin 2? yl) no name ' 3 piel _putdlata C1 £ cout € yoll na ¢ name !4 wll noe >? Title + LE Coubs2tEnley rook Price! i L Cin 2? Prize ' ia x Voie purtdarka 0) £ Couk et hook Jidle = "2% Tle | Cour2e’' book price 2"24 Price; % ihe [Date J int - main £ Book 6." Ps dtO ce sede Malte i ve PB. B. getdata O} Bis Potdade OF Bi acrep} C) 7 2, clispléy Cr+ By.gee CI! Q,. Dut 5 eer ee A, getdlata GO Avactepp ex Put delat f. accept ir’ A.—cligplay-(2" | A, get (7; 1 | A, Putty | 2 i HI Habyicl Trbexidane: Ferg thhentans There __Caulal be L Situation where ue heecl to appl Q ax more 4 pe of Inperitons ta clecine a pyoblem Io. Te, | fa.) }

You might also like