You are on page 1of 20
boas bmata “aim of 00? = ianHto.’ bind togetner tne Onde dhe -functong -Rnaty/ operate on Ftnem sol mo other part of he code “Can -access cthis davai, mlignexcept: thia-) function» s £ - TT ‘ y ott Class + TR-\i8) a user defined) data types, which= hedg Ss own data memberg and member -Punctionaiywh con be accessed and used by creating an Inst of —tnat clas. Object : When a cass js defined no memory is allocated but when ft 18 “nstontiated Ci-e,object iS created) memory iB allocated. Encapsulotion: In oP 7 Encapsulation is defined as binding tegetner the dota and the functions that Mani pulares ¢ z Abstraction: Abstraction means displaying only essenrial information and hiding he detcial. sAbsrvaction using ctaskeg + Absraaction esi, Header Piteg Cmatn-h —> pow Polymorphism : “In Simple words , we can de Fin aS the ability ae le { of a meSSage tp be displayed — more than one form. + Function overteadi “| Operator overtoadi a G tat sum C0 26 , a) ‘mt gum Cio, 20) ee heritance + “The seapabittry, dina selasa = propertien and charocteriaricg from Sts cated Rnhertxances, Se oe, Subciass~ sats ne 6+) Superciass Be tier Re aw ; ; Dymamte Binding ! “tn dynamic binding, the code be execureN An vesponse 40 fuhetion> eas » decided at yun time, a Congtructos: A constructor i8 a member function o Q@ class Which {inittalfzes objects iofiia? classe Constmuctor {% automatically calied When the ok creates - Tr hos 7Same name as Ctwss Atselt .oiGit lu) Consrsuctor don't have a) Serum type, 4, Defavik Constwuctor _CNo porameter Passed) _ A Parametrized Cons+vuctos mR f HBS Acopy, iPoasre ctor Se 3 in i = Desteuctos tn Ctt * Perived clasp destwue oe Invoked firat ,-then the bose claza de wit! be “invoked, Access Modifier: fublic — can be accessed aby” Private ix Can be Accessed _bn\y iby 1a 1 Fam: Clasp Cfnaccestnle ourside the |Claas) oOrected = Tr iB also 4ndccess\ ble ON Class but. Compile time foly Function YC n => Run ttme Poy” a eat =a UL Function “eventdin Occurz J When a. de lass has Q_ definition Vof cae. or more members of base cas , - of Data Abs trathohs 52 Avoid W code Sroucture Vs closs + Gees Smposttant SiS NS Security. Tot OTSA A Srouctuse %2 Mot Secure and cannot © RR membes function and variable” \B Secuse and can hide %*E Bestcuins derchila. g SFR é local Classen tn C++ + A class declared. Inside @ function becomes local to “Hat Pun@tion ond 12 alle \oca\ Class - Ate tne mernode of leca\ Hee Virtual Function and Runtime Poly morphism ¢ function if a membew MPunctioniaw) A virtual 1S deciaved within a base dloagvand redes (verriden) by derived claze FuncHora are declared with Vistual Keyword 1 base Casa, jHolt) 70g) SSRN Exceptfon fond ind. Rn C++! soy 2 vepreser a block of ade that § an €xeeprtion . ovesmnt a block of (code When error if “Mrowm (slo) Use9 “Do —“Hrow On ex “Were [sa Special. catn bie 7 Catan Dis Sat catches all types et ervon' + Taline Function = Inline iB a Yequest not command , vue TH 12 function hat ig expanded 4n_ line When tt Called. When +ne “Inline fmction ts called ,» whol Code get “inserted or Substituted at the Poin of function call, Sale verumn—ty pe Func ) Hani 6 Ray t il __* Function Overloading 48 a feature mn Helo\ or) more! fonttions © Gan. have different parameterg « Crt Where same name — b Ne igre : ' j Noid prink Cant 2) { Cout “Mere will be onwyin copy ef Static member variab for -ne Whole clage. ibys Exs Class Account Fi 4 private 4 fox valance; Sto fox Tot 7 public + Noid SetBalance Ctat by — i batnce =b ; b Wintalised outside oss Float — Account 2% Yot Void main f Account aay B “declored’ ag cr + aw ana THIS RS Dy ‘funerion “in a Cess (+ Static 2 NF ane SE 96 eae Static > member functiong =) are” Tanowed 40” a ony -he Static data memberz ot other stat member founesiong , pnrisnel YS e Constructors». qa (ays 2 Constructors ig an Special member. yotun Chlonin/ia® = | Class. Er _|s automaticaly Fnveked when 1S) created. se 2 hes | no return type 7 3 Constructsr has Same vame as Class Hse > I we do not specify ,oanen Gre compiler generat a default Comptructor for us Serre 7 Mg 2 p a > Conavriever J benkoe De Favre Porometerized copy ClassLname() - so@lass_name, Cparamerera)) sans.) update) oct 1 jem vpdate Cte 0, sak) oe a © Son Bbasi0 jb uw > -G= yawn SN SU be ipa ipe 26 4! Ror vatguey enegll T Compiler generates two constructor by fself 4: Deta Grstructor a f 2. Copy a ¢ : sh Sha ig created by uses Bort} any of -tne constructor sthen “default constructor Will Compiler + Construction overloading funerion overloading , N v mor be created by” can be done just Whey Trene Dejavit Gempiter’a) Copy Constructor Can done only ‘shallow Copy - 3 — al Coints +o Sam er ees memery \eat pee “4 ob) U ob} 2 3 Deep Copy is Possible only with user defined cons mm wer Y defined copy _constuctor , we make cove golnters ob copied opject its =o new memory * my Can we make Copy onstructor private 7 Yes Wey argument to Copy Censtructor must be passed” cs a” veference 2 Becavse tf we pass valve ,-tnen Tr would made to Gil Copy constructor which becomes Ton=ten . Ser (eo peg \ pj Sea Deep Copy deleter “an object, 3 Destuctos don} Bake! “any= argument andy a = Fave any yveturn type La oeNies 5 Only one destructor ig possible Bere ctor: eamectd bat sen ante . bie a Ey oan desivuctor — doeane destroy oblect fT iene lest function that “inioceaineerars opject'd hal ey ee 5 ee Resourd Ez Destructer {% used, So that before deletion of bj we an free space ailoaried for thia Vesoure, Ble ib ob) OB deleted then Space Allocated for obj Wil be Free but resource Cocanit Operator Oven C++ hove) the ability to provide special meaning 4o jhe operator. i class Complex bay Ae ewes Gopi operatar + (Complex Rei) x Complex ren 59 t eZ Dea evr ay TBD = 02d je int main 4 @ =a +ce2r Ae Sr" can't add Complex 70'S cas |e Cane define a fonction “wit Tame le SP oboe |__meed write operator Keyword beyore Soy weR" use” @ qn eperater Are this . 5 Ae Friend C\ass 2 . A friend claga can access ane Private ana pre C memberB. of other class | iM Which Tt is declared Friend. +a TWere Ga be friend clase and friend function Ex: Class = BOX { ! | a privere doable width ; 3 pobiie + Ve d > friend Void printWidth (Box box)) Noid Serwidin¢ doble wid)j lm y f 1ofeas 2 Noid» Boxs+ 2 -Setwidth (Box double Wid) 4 Width= wie; y > oe ! Nold print wien (Box box) >> 320k I 4 Govt maind > x219Mn Bok Sb x Ho/onmnay & box Seti ate ( oy é Print Wicttn Cox) 5 e Thhér tance SnD TSA b. < = ae = S__praess of tnhertvig “properties and & x existin a of fee Sete day eae — Ygmeelass. . Bose_clocs RC Sa =i | es | u *. a 3 ae Car | Classi Spore sSar /tiPeblion Gr (i = = | Ce No MEY § epany 5 a a “Types of Tnneritance + cece y ; sildega: 38 ie a. Single Inheritance : v wiv Sete cloas B + public A =i 7 olor ai — 3 d WD al as ES sb). Moitileve\ Inheritance + Glace Bux public A. Galore ~ “i re Myitiple “Inheritance nf ALT MOUAASS LAL 22 closs AZ ad f di a lass Bt public Al, public AZ ae $3 A). Heirarchia\ | Inheritance cless BL: Poblte A 4 by SS pe I! DoT he es Cee a by t j > Nisibitt Mode A = bose loss B- Sub Cass A i3V3/ rb lop 2205 F Peblic member. Win be poet ?n @,. and. will grotected . A a. os visibility, mode is Private thea both Proteaed i] — ana gobiicN member of A wil be Private “member qs) q 2DhS — =\8 a Relationship is alwayz “mplemented az 1a public An hertténce . Constructor and Destructor In —anheritonce First chia class constructor win tun during creation OF cbject Of child (clss , bot Os Soon Ye obj 8 | reared chi \d class = Constructor YUN and 4 wil cal) ~anstiweror of 48 gent leas and Afher the ecat of arent dass consisuetes «= Tt BEIMEe FH on ear | &ecstion , res porenr _construces call = = eo) 2 AO) (2 nipry en pribid rsv0 bortsm\ qn case gh desesuctosit: »D) Child destvveltos — exea 1 oprent “dese, executed, Tae SHS RYE a See i™ Fi wa addre Every object in cre hos accesza’ -to 4B own 8 this pointer, ar On important epdinter aa\ied 2 be ie inter, | ee Friend function doean+ nave a, nis! os iem| frends ave ot member, of a claeg. we fonerion have thin pelnter. fo ear Clags Box ‘s 87 s PriNate + 3 SE z far Db K | peelic x SNobdisiser Cnt Qristntesd, Smt hj oorreM 4 snerQ = @; a eneleee oy Ahissbosnaby Th this > h YOAFENOS TT SAV i Ant malin C) 4 ar Boe puns bi ee (No, H) 7 Seber x Merned Over Riain SEAS EUS — “octieved ars ton oan dhe). l 2s x St the a vedefi nition oF 22D 2a ats base Css fy _feturn Private + Aa Qearno 7 pebltcy ~ Nold change-qear (fink gear) Sree! “to » of aS aera nde SLPS +oavF oun raid > de SporigGr + Public Car bn 2) smit= sigma Noid change-qearC Ynt+ gear) e 4 HL tgear > 55 oobd c want oa T z enn a yo I UF [ woo & ant min g Sorts Gor Boy c+ Change -qear (4) 5 sd Ce, BOe Sigma 28 2 °N ital . Fonction?" z A Nirtval finction ig a member function Which Vis __declaved with a ‘virtval Keyword! i ome base and edec\ared Coverridden) %n a desived class. When You yefer 40 @ object of derived Clos Ushs poster to a base clasz, yo can call a virtual fons of hat object) and execute, the derived clogs! Nersion of +e fonction . + They are used to achieve Rion time — Poly morphism - + Nirtval Fonction Cannot be Static and also cannot be Amerion of anortner class. Compiie—time C Early binding) Vs Run_sime Chote Gindi é S Gloss base ‘ 4 public t ; Nirtval_veta print C 4 Goutec “ This ie bose print” << Endl) } — Noid Show C) 4 Gout ce" Base show fon" ee endly 4 . S a | class derived 4 BS IPDS Viw 2255 vw ehogal ae soi nee 4 way 7 No td Printc) Ye > _pailee. ES ee a ae a tn Noid Show) 20 239 oe She B 1eBUb cen fe a ee SSSI Sbpiag Swat “derived bptr x opty > erinko 3 berry > svowd } MW Compiie rime _ -oreean ond SW Naxe Binding 4 ay binding. +502 derived! printers © “Wee Base Stow ‘tun during compiler Rime bet behaviour jydged on bards! of which cloap « fne function iS Mot Virtval shen tt will ailow bindi compile time aha privy fun of obese “eta wil! : binded b/c bprr mepresent baze closs, Bue at yun > +ime topae pois to tne, cp Ok cass deywed) , So FH WIN 5 bind sfendion Pe Gevived at Fun ime. Closs % belong, So bptr represent q pod oireda W Working of Nivtual Function —CN\Tabte > 2 Ptr) QQ ciss cahvaing Vivtval function then Compiler tse Sintwe 7 y/ani anes 5 ? ‘i A Virvval pointer Were) is. created every time _ created for thar class which Contains ray is caied \VTABLE © where vienal fonction \a. one Gev\Ned Class, dunia NPTR [ao al Smit siigm ot Pure Nirtval Function coibai S404 and abstract Class "Sometimes implementation of ai function nner mites) bosexiviolaaz , qSucn a.) Gasca le canned ArawO SD Bet there: cant B im Pement=ten, ar (Shape [ D a ae SS [Evce | Aw pure virtual Hanetion oan css le _ewhieh bo we don!+ have Re 4 Abstract Claas Gt9V 2 Clogs ese leur Jo Veet vetieish 7 “ Oo viral functis any “implementation, we 6 Noitsnu7 Public: Nivfual velar func piers id LS ypSaxS pigs > Ac» cess ia 5 Gbstracn aR + cae Bere S288 pure virtuali > fonetion, > = _ : BRED. otal a “or 5 SA Fee Goes e 5 e* ynamic Constructor ; When allocation of memory 1s done dyaamicall memory _ “allocater “new in using dynamic N class qecks. 4 : poblic Noid fon 4 mmr main’) eee = Tew

You might also like