OOPS Handwritten Notes

You might also like

Download as pdf
Download as pdf
You are on page 1of 20
boas bmata “aim of 00 = ise tte.) bind together tne Onin cine functions thats operate on ‘them Zo mo other part of he code Can “access cthis davai, mlignexcept: thia- function. SFE fn ¢ 20h hel Class + Tk-\i8) a user defined) datatypes, Which herdg Ss own data memberg and member -Punctionsipwh con be accessed and used by creating an Insta of —that clas. Object : When a cass is defined no memory is allocated but when Wt 18 “nstontiated Ci-e,object iS created) memory iB allocated. Encapsulotion: In ooP 7 Encapsulation is defined ag binding together the dota and the inctiong that Mani pulates ¢ £ Abstraction: Abstraction means displaying only essenrial information and hiding he detcial. sAbsraction using ctaskeg + Absrnaction esi, Header Piteg Cmatn-h —> pow Polymorphism : “rn 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, 20 , 3a) ‘mt gum Cio, 20) ee heritance + “The seapabtitty” dina seas = propertien and characterlariog from SAS cated Rnhertxances, Se oR, Subciass~ sais et 6+) Superciass Be ier Re we : ; Dymamte Binding ! th dynamic binding, the code be execureN An vesponse 40 fuhetion> calls » decided at yun time. a Congtructoms: A constructor i8 a member function o Q@ class Which {nittaltzes objects iofiva? classe Constmuctor {% automatically called When the ok creates » Tr hes 7Same. name as Ctwss; Atselt .oigitluly Consrsuctor don't have a) Serum -+ype- 4, Defavir Constwuctor (No porameter Passed) _ Re Parametrized Constvuctos me f BS Acopy, Ponsre ucts See 3 in i = Desteuctos tn Ctt * Perived clasp destwue joe Invoked firat ,-then the bose clazae de wit! be “invoked. Access Modifier: fublic — can be accessed aby” Private i= Gan be Accessed _bn\y iby a1 Fam: Clasp Cfnaccestnle ourside the. |Cleas) Orected = TF iB also 4ngecess\ ble ON — Class but. Compile time foly Function YC => Run ttme Poy” < eat i Go Finetion oversaia Occuxz a When Q- lass has Q_ definition Vof Gre ‘or Anon members of base cass , 5 of Data SAbstrathoh> 52 Avord U code Sroucture Vs closs + ee Smposttart “SiS NS Security. Tot STS A Srouctuse %2 Mot Secure and cannot © RR membes function and variable” \B Secuse and can hide FE Bestcping derchila. 0g SREP é local Classen tn C++ « A class declared. Inside @ Punction becomes local to “Hat funetion ond 12 alle \oca\ €iass - Ate tne mexnodz of lecal Shee Virtual Function and Runtime Poly morphism ¢ function if a membew MPunction aw) A virtual 6 decaved within a bose dloag and rede® (everriden) by derived claze Funcflora are declared with Vistual Keyword H base Clasz, jholt) 70g) TSIEN Exceptfon ona ing. Rn Crt! uy 2 vepreser a block of Gode that § an €xeeprtion . osesmnt a block Of (code When error if “MrowM(si-9) Use9 “tm —-HrowW On ex Tiere (8 QQ Specia\oip cath: “block 7? © catenGes), A+ catches all types et erro: 3 + Taline Function = Inline iB a Yequest not command , vue TH 12 function har is expanded 4n_ line When ¥ te Called. When +ne “Inline fmction ts called ,» whol Code get “inserted or Subetitvted at the pote of Sn) fonction call, Sale vernn—ty pe Func ) Peni 6 Rey BE t / __* Function Overloading 48 a feature mn C++ —whele / sno Boriimerel) Wnttons © an vihove...came manele Al ferent porameterz « Ne ier E } Void print (tnt L) Print Clore rq SvussOHere IRSRNN < oXmedena ig Be J f Noid print Cfloat £) aa sm Cout ce f Here ig floae” cas << End; 4 | Z 2 fi main = : besistrs Piinr GIs ioe = } : | € Supportg procedural ni a AS C ‘doew nor support tne Qoks concept so tt has mo = Support -for_ polymorphism, encapsulation and “inheritance a Subset of Crr @ contains 32 KeywordR ig @ fonction driven lanquage (8 Function ond operator over \oadk asda ta © ig Known as hy Sad +t je Nanquage ,-beea vse bot procedural and ebje oriented programming.) c++ has BuPport For\) poly Prism, Encapsulation © and Annefitance aS % iB aH odfs Nanquageny cxt ize Stperser off Coe Cr+ Contain!) SZ Keywords Cyeliod paivote, \PnO Neste aE ery 7 “Carel AM VOW en) C++ isan: Object driven laniquage wk ua Cre suppertay Function Z ° ditote + ie mot Support tn Cc. operator overloading, # © Goes not Support exception eeseiny C++ dweanle supports exception hand t ary and atch agar Q Goilleetion (of 18 Static «Members in C** *Static variable tn a function When QO variable declored aS. Static, space for tt ger aiiecated for lifetime of the program (defaut Farialized ro o) Even © the function iB called muttiple times) space. for 44 18 allocated once. + Sratic variable %n G@ class » = Declared ‘inside the class body - Also Known @% class. member. vari@ble . 3 They must be defined outside +ne class. Static voriavie doesn'r belong to any object , BUF ane. Whole class x > “here will be onyin copy ef Static member variab for -ne Whole clage. ibys Exs Class Account Fi 4 private 4 fox balance; Stoic fox Tot 7 public + Noid SetBalance Ctar by — i batonce =b ; b Mintalised outside oss Float — Account 2% Yot Void main f Account aay 4 “declored’ ag “ + aw any THIS RS toy ‘unetion “in a Css (+ Static 2 TF ane oe 96 Nee Static > member functiong = are” Tanowed 40” % ony -he Static data memberz ot other stat member Funesiong , pnrisnol YS eConstructora qa (ays 2 Constuctors_ ig an Special member. yotun chionin/iak = | Class. Er _|s automaticaly Fnveked when 1S created. ae 2 hes | no retwrn type 7 f 3 Constructsr has Same vame as Class Hsel > I we do not specify ,otnen Gre compiler generat @ default Comptructor for us Serre 7 1g 2 p a > Conawriever Js bene Defavtt forometerized copy CilassLname() - s@lass_name. Cparamerera)> sass.) update) 911 jem update Cte 0, snk) oe a Y Son Bbasi0 jb uw > +Q=Oyleve 2eNq Su be AeA iowa 26 4! or vatguey enegll ___ Compiiter eneratez — 4 Deta Gnstructor 4 2. Copy ARES amo nconsrructer by Tselh 1 Bot i} any of the aonstvuctor = 12% cragred by user then “dejauit constructor Will not be created by Compiler « Construction overloading can be done fonerion evertoading, ’ v Theas Dejavit CGempiter’a) Copy Constructor Can done only "shallow Copy - 3 aT J Cfoints to Sami A a merry lear + — ej} — opp Obj 2 + Deep Copy is Possible only witr user defined cons th wer’ defined Copy constructor , we mare cove golntera of copied opject pots -to new memory Can we make Copy onstructor private 7 Yes Way arquinent to Gopy Censtructor must be passed cs a” yeference 2 Becavse tf we pass valve ,-tnen Tr would made to all Copy constructor which becomes Ton=ten p U ie, eee cai es © Sar \ enyt "eeh2 Deep Copy deleten “an object, 3 DesHuctos don} Bake! vany= argument ond a ae Fave any yveturn type La ass 5 Only one destructor jg possible Bere yctor: mock) bet sen oat ea . bt a esters desivuctor — doean* destroy oblect ith) iene “test function “that “inioceaiuneerer object's al ey eh 5 es Resoura a Destructer 1% used, So that before deletion of bj we an free space lloaried for thia Yesoure. Ble ib ob) Oke deleted then Space Allocated for obj Wil be Free but resource Gocanit Operator Ouest Crt hove he ability to provide special meaning 4D jhe operator. i class Complex bay Me ewes Gopi operatar + (Complex Rei) a Gomplex ren yo t eZ. De ewes TBD = 62d je int main ©) 4 @ =a4cr As Sr" can't add Complex 70'S cea | 6 Cane define a fonction, “wit Tame le SP bod |__meed write operator Keyword beyjore Soy, weR" use” @ qn eperater Are this . oa Friend C\ass 2 . A Friend claga can access ane Privare ana PS C memberB. of other class | iM Which Tt is declared Friend. ‘* al “Were Ga be friend clase and friend function Ex: Class = BOK { } | 4 privere doable width ; 3 pobiie + Ve d > friend Void printidath (Box box)) Noid Serwidin¢ doble wWid)j lm y t 1oteas 2 Noid» Box + 2 -Setwidth (Box double Wid) 4 Width= wie; y > oe ! Nold print wien (Box box) >> S208 I 4 Govt maind > x919n Bok Sb x Ho/onmeay & box Seti i at ( a); é Print Wicttn Cox) 5 e Thhér tance SnD SAAE é. = = ae = S_praess of nhertvg “properties and & ‘i existin ata of ft Stee Seto an eae — Ygmeelass. . Bose_cloas Cr sa =i | es | iu ~. a 3 ee Car | Classi -Sporte sar /ti/Peblion Gr (5 = eh | Se No MPS § epany 5 = a “Types of Tneritance + cet q ; sildega: 38 a a. Single Inheritance : v wiv Sete cloas B + public A ate =) a 2 olor ai — a d WZ aaa 3 ES sb). Moitileve) Inheritance + Clase Bt Pubic A 8 ~ = re Myitiple “Inheritance nf ALT MOLAASS LAb. 29 closs AZ ad f di be lass Bt public Al, public AZ ae $3 A). Heirarchia\ © Inheritance Gless Bi: Poblte A 4 by ae pen EB BD Tor hee es Ce ms Ly t j > Nisibitt Mode A = bose loss B- Sub Cass A i3V3/ rh lop 2205 F peblic member. Win be petit in @,. and will grotected . A a: e visibility, mode is Private thea both proteaed i] — wi goblicN member of A wil be Private “member qs) q 20hS) — =\8 a Relationship is alway “mplemented az 1a public An hertténce . Constructor and Destructor In —anheritonce First chia class constructor win tun during creation OF cbject Of child (else, bot Os Soon Ye obj 8 | Creared chi \d class = Gonstructor YUN | and 4 wil cal) TGnstiweror of 43 gent leas and After the eeat of arent dass constsuetes «= Tt) BEIMEe FH con eee | eecsttion , res porenr _construces call = eS Ga FAO) ©) nipry seni pri bid rsv0 bortsm\ fn case gi desesvetosyi: »D) Child destveltos exea 5 open “dese, executed, Pe SHS RYE a See Fi wa addre Every object tn crx hos accesza -to it own 8 hia pointer, ar On Amportant pointer aa\ied ie Lb ie inter, ee Friend function doean+ Nave a, “nis! a= iem| frends ave ot membern, of a cagg. ON fonerion have thin pelnter. fo ear Class Box Ss a7 s PriNate + 3 SFE z far Db K ; peslic x SNobdirsiser Cint Qristntesd, Smt hj oorreM 4 sne>2Q = 2; peas £0 Oy Ahlss bsnepy Th this > h YOAFENOS TT SET i Ant malin C) 4 rea Boe puna bi ee (No, H) Seber x Merned Over Riain HERS RAS — “achieved aks ton an dhe). l 235s x St the a vedefi rion oF 23D 2a ets base Css fy return Private + Aa Qearno 7 pebltcy ~ Notd ehange-qear (Gnk gear) Ya “So of aS ere idle SLPS tau louRi rid > de SporigGr + Peblic Car bn 2) smit= signa Noid change-qearC Yn gear) e 4 HL tear > 55 oobd cael ola T z ear yy [ wood & aint min g Sorts Gor Boy c+ Change -qear (4) 5 tag Ce, BOE Sigma a8 SN ital . Fonction? z A Nirtval fncrion ig a member function Which Vis __declaved with a ‘virtval Keyword!) i “me base and redec\ared Coverridden) %n a desived class. When You yefer 40 @ object of derived Clos Ushi poivrer 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 Ron time — Poly morphism - + Nirwval Fonction Cannot be Static and also cannot be Amerion of anotner clogs. Comptie—time CEarly binding) Ve Run_sime Chote Gindi 7 S Gloss base " i public t ; Nirtval_veta print © 4 Gute “ This ie bose print” << Endl) } — Noid Show ¢) 4 Gout" Base show fon" ee endly 4 . S Z | class derived 4 ES IRDIVESd Viw 2255 vw ehegal ae soi nee 4 way 2 Noid Prinkc) Ye > _ pail. ES ee ae ao Noid Show) 20 239 oe She B reBUb cen ft ee eee SSSI SbpiaG Swat “derived bptr x opty > rink 5 berry > svowd } 4 Compiie ime _ -oreean ond - Naxe Binding 4 ay binding. +302 deriwea! prints =: © “Wee Base Stow ‘tun during compiler Rime bptr behaviour jydged on bards of which cloap « fne function 1S Mot Virtval hen tt will ailow bindi compile time aha privy fun of obese “ctase wilt : binded b/c bprr mepresent baze closs, Bue at yun > +ime topae pois to tne. ce Ok cass devwed , So FH WIN b- bind “fendion Pe devived at Fun ime. Closs % belong, So bptr represnt 7 pod oireda W Working of Nivtual Function —CN\Tabte > 2 NP tr) a class cahraing Virtval function then Compiler tse Sintwe > ani lanes 5 ? i A Virvval~ pointer (ere) is. created every time _ created for thar class which Contains ray is caied \VTABLE © Where viel fonction \a. one dev\Ned Class, dune NPTR mea al Smit slign Pure Nirtval Function coibei S404 and Bbstract Class “Sometimes Amp\ementation of ai function nner fiw hem) basexvolaaz , Suen a.) Gass le canned drawO SD Bet there: cant B im pement=ten, ar (Shape [ D a eo oe [Evae | Aw pure virtual Hanetion oan css ie _sewhieh bo we don!+ have Re 4 Abstract Claas Gt9V 2 Clogs, ese leur Jo Veet vetieich a ~ Oo viral functia any “implementation, we 6 Hoitsnu7 Pubic: Nivtual vei fon piers 0 ASSAD pigs > Ac» cess ig 5 Gbstracn Re ate cee Bere S288 pure virtual > fonetion, maa _ : BRED: tole a “Sor 5 SA Fee aes e

You might also like