Docsity

C++-OOP-Interview-Notes-Series, Schemes and Mind Maps of Programming Languages

Partial preview of the text

Download C++-OOP-Interview-Notes-Series and more Schemes and Mind Maps Programming Languages in PDF only on Docsity!

OOPS in C++ The main aim of OoP is 1 bind togetner the | .data_and the functions the operate on them so_ _that_no_otnery pavt of the code can access this _.data_except this Function . 2 AruL Kumar Cunkepin)- __TYPes or OOPS NOTES GAWLERY( TELEGRAM) . __ [encarsuiation 7 Abstraction ~ Class : holds It is @ usey defined data types, which its own data Members and membev __|Punctions, which can be agecessed and used a | Cveating an instance of that class. ject. C Fecaiemared: bik wines fj CG. naman is created mem defined no memory _ emoxy is allocated ._ = Eneapeuiatin ont Th OOP, Encapsulation is. defined AS binding together the data and the Functions —}- chhat_manipulates -them._ a ee —=>- _Abstvaction = Abstyaction means displaying only essential information and hiding the d erails. Abstraction using classes Abstraction using Header Fites Cmath: hs Powel =>“ Polumorohigm : In simple words , we can define polymorphism as Qn ability of a mM essage te be iAisplayed in_Move than one form. 7 Opevatoy Oveyloading function overloading | L, int _sum (10,20, 30) int_sum Cio, 20 ) Thhevitance | The capability of 9 class to _ Dedieepopeviles na chavdceedistes fyom ‘anOthey class is Catted {nhevitance.- Subclass SuperClass ATUL Koma (LuKceD ay) Reusability NOTES GALLERY (TELEGRAM), hh dynamic binding. , the co ode 2 +0 be < a |\_yesponse +o function cat is _ldecide ea ok Son Sian, A Briend class can access private and. _Pvotected members of Omer class in which Lit is declayed as Friend. Ex i- Fyiend class Bs ATUL Ke Re Notes GALLERY (revenue), “Thhevitance _ 2 Class Su belass : 4 accessmode . _baseclass _ P= B- Hubyid Combination ef one oy More type. Cc | Polymorphism Operator Overloadin 9g. — Compile time Poy Function overloading — — Runtime Poly L> Function Overviding occuys When @ i deive. class has Q definition of one oy more uMmembers oF base class. - | ___Advantages of Data Abstraction _ Avoid. code du uplication and _inc “inc. reusability * Can change internal implementation ef class” a —Histesenae uy. ATUL comet (Lin KeDIA). = NOTES GALLERY (TELEGEAM) | ee VS —— Most im an iFfex i curs Yy - A Srvucture e not_ cocuve. and cannot nide (its member function and variable nile clas iS secure and can nide its programming _& designing details. ___lpecal classes in cre: ee A class declayed inside q function becomes loca) +o tnat Function and js called \ocal CAASS - — An ane petals oF jocass class mus ust_be. _ ideFined inside the cigss only . - \/ixtual Lunction and Runtime Folumoyphism + LA viytual Function is a member Function ~ [eaten is declayed with a base class and. nd yedefined Coverviden) by devived class. _ | functions cave declared with virtual pase class. _ Function Overloading _ Function ove loading fold _pvint Cnt i 1 ; cout << “Herxe_ is tnt tid i cc Semel is Q feature in ctt Where two ov more functions can nave _ same name but different parameters. — Void print (float i_) Cour << “Hexe is float" << i <¢ endl, i Jat main t print (10) 4 print (10-12) 5 ne GC and Cre Ca+ C are procedural PyroAYaAM . language , because it Su pport both _proceduy¢ 2 and object ovlented AS c does not Support Proavammina. Ds J the pops Concept so it Crt nas Support Polumorhicm has NO Support for polympyphism , encapsulation an 4 encapsul ation and inhewitance as it is qn inneyitance - OOPS lanquage. C ig q Cubset of Cte le Crt ig a superset oF C. = e Ctt iS \cnown as hybrid > * Ctt Contain 52 Keywords C public, privare ) protected, Tyy , catch, C Contains 32 |Keywords | : throw) C is a function dyiven |® Crt is an obsect language. ___ _| dviven language. Function and operator. je C+tr supports function overloading is not | & opesatoy support in Cc. t Overloading - © C does not Support exception handling. | handling using try e Crt Supports exception L | and catch. _Styuctuye is -Q collection of dissimilay | a ATUL Jeo MAR (LINKEDIN). am Fe tic M } «in ctt NOTES GALLERY (TELEGRAM), e _Static vayviable in @ Function : "yinen Q Variable is declared a¢ static, _Conctyuctoy_hac came name as class itself. > IF we do not ‘Constyuction overloading can be done just i\ike function overloading . _ __.Defauit Ccompiier's) Copy constructor can done_| Only _Shallow_ copy: ( Points to same __ memorxy location ” Obj 2 — ATUL eum? (LINKEDIN) NOTES GaLlety(TELEGR™ ), _ “Deep2copy is p ossible only with user defi ned Constyuctors - Sey in (axe) Onstvuctor wie make _ i \Suve that pointers of copied object points __.to WwW v. on: Can we make copy constructor private ? Yes. Ulhy ayqument +0 copy constyuctoy must be _____ passed @S a yeference 2 oe Because if we pass vaiue , then if would Made fo Call copy constyructoy nrhich becomes non - terminating — ; - | =: — Deep copy. int main C_) oe atu eumnet (Ling edn) | NOTES GALLERY (TELEGRAM ), JC = £1 + 0o _As'+? can't add Complex no's divectly. So we ican define Q Function with name + but we | —____Need wiyite opevator Keyword. befove it: £0, IWlé can use all operator ike this. r xiend Class 1A Friend class can access tne private. and ipyotected Members of Other class in which it lig declayed as friend. Tneve can be Friend class and Friend Function. |Ex: Class Box I __t private: double width » public » | fviend void pyintwidth (Box. box} _ veld setuldth (double Wid) 5. i : Noid Pp inttidth (Box | box do _ | x Void Box: setulidth (Boxdouble wig) _ — f£ Wigh= wids >} 4 cout<< box. width; » _ = = ky int main (_) { Box box} box. Setwidth (14); printwidth Chox ) 5 us ce iS Q pyocess. of nhest ing properties < “and benaviouy OF existin Q_new class. Te1ass der_ class : visibilit pe Class Ca% [ ciass _Spost. Cay: public { ; cay { ATUL komme (LACED IN) ys NOTES GALLERY (TELE GRAN) | Class Base Class f +; Class C: Public. BB. IP B is Supciass and visibility Mode is public | Class A: [Public *] B | t : foo _ a = then public member of. AL will be public in GB. and | protected will pywrotected —_ TF visibility mode is private tne both_pratected _.and_ public member of A willl be private _ —_—. Member of B. _ Is_q ‘Relationship is always implemented as_ _@&__public inhevitance. _ nd uctoy | itance Fivst child class constyuctoys will xun during creation ef Object of Child class, but as soon _ as Obj_i is created Ghild class Constructor wan _ and if will call Constyuctor of its paxent class and after the execution ef pasent class constyuctoy it_wih wesume it constructor execution : | Child ws BL) i on addyess thyough an important. ace called | tic pointer - aoTes way a (even Rn ney. __[Eriena Function doesn't have @ ‘this’ painter» — —Ony member function have _4this_pointey- —_ Class Box Pyivare : inf lo bih: Public + a vord set Cint I, Intb. inth) {nis 7 | ; this 7 b this 7h Bi int main ( J { —— Box b; _ _b- set(5,10,4) 5 ethod OverRiding ( achieved at yun Hme) — — {Tr isthe vedeFinition ef base class Functton |. its devived class , wiith same yetuyn | Tepe ana “same_pavameters. : while Method Overloading 1S achieved. at. _| Compile time : Vistual Function A Vistual function ts a member fonction wihich is declaved with a‘ virtual Keyword’ _\in_ -+he base class and yedeclayed —_— Covervidden ) in a derived class. j _lathen youve Fer +o ee of devise leas using _peintey 4 - base class, you can} iCall a virtual a of that object and |. execute tne deyived cigss'S version of the function. e They ave_used to achieve Run time _poliymoxphicm - Virtual Eunction Cannot be Static and also cannot be Friend function oF anothey class. _Compile-time CEavly binding ) | Vs Atue Komme (Linkedin). Runtime ( Late Binding ) Class hase { Publics ee { cout <é¢ This is bace pxint "ee endl> Na _ Noid Show (_) : : L cout << “Base show fun” Z< endl; -_> lass deyived Joc t Public: _ - Void print) — deourec" dexived Print" << . endl ; 3 NVotd Show ( a - L cout <<“ derived show Fun” <é endl; , — x ATUL Jeumpn (LINKED IA) int main C_) NOTES GALLERY (TELEY, £ base * boty; dexsived ders bety = & ders bpty => Print o)5 (1 Run time boty —> Show (); // Compile tHme | | utput: a 8 dexsived pyint _ Base show fun _ {1 Lare Binding I Eavly binding 20,