0 ratings0% found this document useful (0 votes) 63 views20 pagesOop
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
yooPs) Ans C4
i
bStamesbmata aim: of) 00? = laste? bind.» kogether th
120
dnd= athe functiong that» operate on ae =
mo other part of he code Can access this dato
mlignexcept this -Rinetion » s c
Class + Tk 18; a user defined) data type» Which» ho\dg
Sts own data members and member functiong:
con be accessed and used by creating an Anstance
of -nat claga.
|
Object : When a class is defined no memory is allocated
but when % i8 “nstontiated Ci-e,object is created) |
memo iB allocated,
t
Encapsulation : In oP , Encapsulation iS defined as bind!
togetner the data and the functions that “mans pulates Mt
¢
Abstraction: Abstraction meana display ing
information and hiding —he detail.
sAbswaction using claskeg
-Avstaaction usith, Header files Cmatn-y = powd)
Only essenrial
ag
Polymorphism + —h Simple: Words We candace poly
mee. tthe ability of a meSsage +p be display ed
mere than one form. 7
+ Function —ovevtoadi
+ Operator overtoadi
"
G
tne tum C10) 26 , 39)
‘mt gum Co, 20)or,
Thheritance + “the Ga pabiitny oF a-elass +o. “der SUSE
properti eB and charocterlaticz
iS catteg Inheritance,
« SubClass
+) Superctass ta79
io Reusabtiity, a oe
q
Dyra mite Binding > =H dynamic binding , ne code to
be execure: Rn wesponse 40 fihction® ean te >
decided nartbo myrun ct ean
rom another claas
Conptructons : A conStructor i8 a member function of
a class Which inittalizes objects ofivah, class% Hq Crt
Conssuctor i automatically catied When the objeck
createa -
TR has *6ame name a8 Class Rrseft .oig¢Hiuhs .&
Consrsuctor don't have as setum +ype-
ae, Defaule Constsuctoy CNo poramexer Passed)
Re Parometrized Consvsuctos
3. Copy Gonsteuctd¥ Inter? /nsidoNen Sse
q .
Desteuctos in Crt * Derived claay desteuctor Will
joe Unvoked Firat, then -the bose clasz destsicto¥
will be “invoked, és
Acceaa Modifier! fublic —)can be accessed’ ccbynany class
Private !~. Can be accessed bry iby 11a fanetiod ig= a om
Provected = TX ia also Anaccessibie outside the
Clase Einaccestble oourside -theiClasa) 5
Class but. can be saccessed . ley Qub clogs ot
thar class » io eis 1 adeany ess — Medi fiey
defau\t the a
will be pxive
Notes rf We do wot specify
Qnaide the class ther! by
modifier fox —-the member
Grenticie ch wuAmetmend class” can aceees
and protected members of other closs in wh
fr is declared as friend. a
Ex friend class 8;
2 mhe vitrance,
Class Subclass 2 acessmodé ~baseclas
=
t
a. Single mheritance
v
2. Multiple Fnhevtrance
[gat none
es
4+ Weerarchical nhertrance s. Hybrid
LA Combination 2 F
IBIAS Or more, tViPeiey
iz aay 3
:
i j
Polymorphism
2 Operator Overloading
=> Compile time Poly 23 Function Serena
> Run ttme Poy
Lb Funetion “overtdin
Oceusg When a-
Class has Q_ definition of
one or more
member2 of base cagAsvantagex of Data Abstraction 2 a a
« Avoid) code duplication “and Fne. Beusavility. é
» CAN Change nresnal @mplementation of cies
andepeniendiy . Reianviad snail
q
Srucuye Vs closs + Most Important difference
%S Secussity. a
A ersuctube %a mor Secure and cannot Shite
eB Membes function and Variable While class
WB Secuse and can hide %# poe
eae detcfilz. 3
QV
0
local Claszez “in C++ + A class declared “inside @
Punction becomes local to that Runetion ond 8 exiled
\eca\ loss
All. the mernodg of local class must be détined *
Rnside the ctass only
Virtual Funetion and Runtime Poly morphism +
A Virtual function ig a _membérr Puncion “which
16 declared Within a base ‘claag and redefined
(@everriden) by derived clage {
Functions are dectared with Viwtua\ Keyword 17
brov
bage Clase
Exceptton Hon alin caviar { q
ey 2 represer a block of code -that dan Wheew
Qn exception » ion apn
Carey + repvecant a block of cose mihat Ger executed
When error \B) throw, (oi-o) smi
Sow! Use to “HYOW On exception:} Caters)
Tiere (2 QQ Specta\)-carth block 7? = §
At catchez all types et error:
+ Taline Function
= Inline iB a fequest mot command , Yd i
TF 12 function shar {3 expanded An \fneé When tt ig
called. When +ne “inline fnction ts called , whole
Code get “nserted or Substitvted at the pote ort
function’ call,
‘ane vewan-type fund)
ER tb Sey
+
* Function Overloading fe a feature Yn
*wo or more finttions can hove
same
At feren+ porameterz .
areal a }
Void prink (tat 2)
L Gout
Petnt ¢ 142) . sapaeeaecias
5 33S ae
= tS Cae
aguw © Svupportg Procedural er
blw
Cand HHS
@
nf
ansd rate Sioa
ig Krown as hybrid
Crt
i vel Nanqvage , because st So
! bot Proceaura\ and object
iz oriented — preg Yamming .
8 ABC ‘does not support tne [© c+ nas RUpbort Corll poly aor
ooks Concept so % basi no “phism, Encapsulation and
_ Support for polymorphism , Anhefitance as % ig Qn
[ encapsuleton and Sn herttancer|> onfs tanquageny sitet =
ZB CiB a subset of CHY eh Copley Stperser of Cc
3A @ contains 32 keywords + Or+ Contain’) S2 keywords
Covbric, paivate, Rrovected |
o apy) “Barely > ANVOw a)
“5, € ig a finction driven Ciao «Grr tevan Se i
yh v | aaa <
& Function and eperator overloading) + Crt” supperts/ Shute Z
is mot Support nc. opertttor oN er \odi Z
F: © deez not support exception [+ C++ daesdar =a 7%
) gens =H exception rept ust
| ay and etchq Collection (of dissimilor alee
+ Serve in
+ Static «Members in Ct*
eStatic. variable tn a function : When O variable
declared aS. Static , space for ‘Sir ene a\iocated for
Wfekime of othe -progrom - (defaut farialized oe 0)
Even © 4ne fonction i@ caed muitiple times,
Space. for Tt 18 allocated once.
« Sratic variable in @ class .
— Declared ‘inside the class bedy 5
— Also” Known a2 class. member. varidble -
> The “must be defined outside tne class. a
| > Static “voriobe deesn'+ belong to any object , bur
| ane whole Class , N ug
i one: -
DP TMhere will ben only n copy of Static member variable
| for ne Whole claaa . >
Exe class Account
ft private :
int balance;
Stave fre Tot ;
fi
Publics pe
Noid SetBalance Cont b)
ee i babne =b; 9
b
Wintalised ovtside doss
Float — Accoun+ +2 Yo4
= 35F ;
Void mainpbject{ Pea mab “Reser eetared cama a a
eS Stove | Account "jae 7 spay Serena
THSITHS HOD
+ Staric — tunerion in
7 x
a Qtass
Fence sH= oo aie
Static > members €ynanong 1s) are eral wed isto occe
ony ne Static data ~~ membera or
member funciona ,
eConstructorz
qo (a'yalgrvad) Hunts
= Constructore ig an Special_member. yofun chlominjiak the
Class. Tr is avtomoteay Fnveked wnen an by eck |
Ig ~ created: >
> Hr hes n°. return type: K Be
3 Constructor has Same vame_ as; Class Stseth +
5 Xf we do not spedfy , then G++ aompiler generate
| Q@ default Comp@tructor for us. 4
Sabie
as Consweror
fo.
Noi y oct
Defourt Porometerized oa
Claselnamet) © pn@lass_name (paramererg)') 9 aiess_nal
la
Update) 90 TY mvpdare Cte x, aun © of | fupes (
4 YP San
=bd=10, Wooti| seq ou
Altea i rapst269 T zombo sare sie ny VotQuyt 21
fy= 2
Compiler qeneratez — two onstrucror by nESeN =
1 4: Defadir Constructor
fe
Fee 2 Co Constructor
mm
Te 1
ig crated by vs
Bor tt any of the cons +vuctor
mor ee create b
shen “default constructor Will
__ Compiler -
Construction overloading can be done jest Mey
funerion overloading , Se
¥ rrenola
Dejav+ Compiter’s) Copy Constructor Can done only
Shallow haw
om
-—a<— 4 Cfoints +0 Same ~
a. memery leer r
_-e-@e om
op u ob) 2 oe
Deep es is Possible only win user defined cons
| Th vser ¥ defined Py gonstuctor , we make sore ant
gointera of copied object polwts to new memory \e¢
Can we maxe Copy Son structor private & Yes
Why a to Copy Constructor must be passed
os “veference 2 j
Because tf we pass valve ;-+nen Tr woua made
4to ail coy constructor which becomeg Ton—tenminat
Roane
tbs —s—]
obj t oj 2