Nothing Special   »   [go: up one dir, main page]

تلخيص

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Top50OOPsI

nter
viewQuest
ions&Answer
s
HereareOOPsint
erv
iewquesti
onsandanswer
sforf
resheraswel
lexper
ienced
candidat
estogett
hei
rdream j
ob.

1)Whati
sOOPS?
OOPSi sabbrev
iat
edasObjectOr
ientedPr ogr
ammingsyst
em i
nwhichpr
ograms
areconsider
edasacoll
ect
ionofobjects.Eachobj
ecti
snothi
ngbutani
nstance
ofaclass.

2)Wr
it
ebasi
cconcept
sofOOPS?
Fol
l
owi
ngar
etheconcept
sofOOPS:

1.Abstr
action
2.Encapsulat
ion
3.I
nherit
ance
4.Poly
mor phi
sm

3)Whati
sacl
ass?
Aclassi
ssimplyarepresentat
ionofatypeofobj
ect.I
tist
he
bl
uepri
nt/
plan/
templat
et hatdescr
ibest
hedetai
lsofanobject
.

4)Whati
sanObj
ect
?
Anobj
ecti
sani
nst
anceofacl
ass.I
thasi
tsownst
ate,
behav
ior
,andi
dent
it
y.

5)Whati
sEncapsul
ati
on?
Encapsulat
ioni
sanat
tri
buteofanobj
ect
,andi
tcont
ainsall
datawhi
chi
shi
dden.
Thathiddendat
acanberestr
ict
edtot
hemembersofthatcl
ass.
Lev
elsar
ePubl
i
c,Pr
otect
ed,
Pri
vat
e,I
nter
nal
,andPr
otect
edI
nter
nal
.
6)Whati
sPol
ymor
phi
sm?
Polymor
phism isnot
hingbutassigni
ngbehav
iororvaluei
nasubcl
asst
o
somethi
ngt hatwasal
readydeclaredi
nthemainclass.Si
mpl
y,pol
ymor
phi
sm
takesmorethanoneform.

7)Whati
sInher
it
ance?
I
nheri
tanceisaconceptwhereoneclasssharest
hestr
uctur
eandbehavi
or
def
inedinanot
herclass.I
fInher
it
anceappli
edtoonecl
assiscall
edSi
ngle
I
nheri
tance,
andifitdependsonmulti
plecl
asses,t
heni
tiscall
edmult
ipl
e
I
nheri
tance.

8)Whatar
emani
pul
ator
s?
Manipulat
orsaret
hefuncti
onswhichcanbeusedi
nconj
unct
ionwiththe
i
nserti
on(<<)andext
ract
ion(>>)oper
ator
sonanobj
ect
.Examplesareendl
and
set
w.

9)Expl
aint
het
erm const
ruct
or
Aconstr
uct
ori
samethodusedtoi
nit
ial
izethestateofanobj
ect
,andi
tget
s
i
nvokedatt
heti
meofobj
ectcr
eati
on.Rulesforconstr
uct
orar
e:

 Const
ruct
orNameshouldbethesameasacl
assname.
 Aconstr
uctormusthav
enoretur
ntype.

10)Def
ineDest
ruct
or?
Adestruct
orisamethodwhichisaut
omat
ical
l
ycall
edwhentheobj
ecti
smade
ofscopeordestr
oyed.Dest
ruct
ornamei
salsosameasclassnamebutwi
tht
he
ti
l
desy mbolbef
orethename.
11)Whati
sanI
nli
nef
unct
ion?
Aninli
nefunct
ioni
sat
echniqueusedbythecompiler
sandinstr
uctst
oinser
t
completebodyoft
hef
unct
ionwher ev
ert
hatfunct
ionisusedinthepr
ogram
sourcecode.

12)Whati
sav
irt
ual
funct
ion?
Av i
rt
ualfunct
ioni
samemberf uncti
onofaclass,
anditsfunctional
it
ycanbe
overr
iddenini
tsderi
vedclass.Thi
sfunct
ioncanbeimplement edbyusinga
keywordcall
edvir
tual
,anditcanbegivenduri
ngfunct
iondeclarati
on.
Avi
rt
ualfunct
ioncanbedecl
aredusi
ngat oken(
vir
tual
)inC++.I
tcanbeachi
eved
i
nC/Pyt
honLanguagebyusingfunct
ionpoint
ersorpoint
erst
ofuncti
on.

13)Whati
saf
ri
endf
unct
ion?
Afri
endfuncti
onisafri
endofaclassthati
sallowedtoaccesst
oPubli
c,pr
ivat
e,
orprot
ecteddataint
hatsameclass.I
fthefuncti
onisdef
inedout
sidet
heclass
cannotaccesssuchi
nformat
ion.
Afri
endcanbedeclaredanywher
eint
hecl
assdeclar
ati
on,
anditcannotbe
af
fectedbyaccesscontr
olkey
wordsl
i
kepr
ivat
e,publ
ic,
orprot
ected.

14)Whati
sfunct
ionov
erl
oadi
ng?
Functi
onoverloadi
ngi saregul
arfuncti
on,buti
tisassignedwithmult
ipl
e
parameter
s.Itall
owst hecreat
ionofseveralmethodswiththesamenamewhi
ch
di
fferf
rom eachot herbythetypeofinputandoutputofthefunct
ion.
Exampl
e
v
oid 
add(
int
&a,
int
&b)
;

v
oid 
add(
doubl
e&a,
doubl
e&b)
;

v
oid 
add(
str
uctbob&a,
str
uctbob&b)
;
15)Whati
soper
atorov
erl
oadi
ng?
Operat
oroverl
oadi
ngi saf unct
ionwheredi
ff
erentoper
ator
sareappl
i
edand
dependsontheargument s.Operat
or,
-
,*canbeusedtopassthr
oughthef
unct
ion,
andithasi
tsownpr ecedencetoexecute

16)Whati
sanabst
ractcl
ass?
Anabstractcl
assisaclasswhi chcannotbeinstantiat
ed.Creati
onofanobjecti
s
notpossibl
ewithanabstractcl
ass,butitcanbei nheri
ted.Anabstractcl
asscan
cont
ainonlyanAbstractmethod.Javaallowsonlyabst ractmethodinabstr
act
cl
asswhi l
eotherl
anguagesal l
ownon-abstractmet hodaswel l
.

17)Whati
sat
ernar
yoper
ator
?
Theter
naryoper
atori
ssaidt
obeanoper atorwhichtakesthreear
gument
s.
Argument
sandresult
sareofdi
ff
erentdatatypes,anditdependsont
hefunct
ion.
Theter
naryoper
atori
sal
socall
edacondi t
ionaloperat
or.

18)Whati
stheuseoff
inal
izemet
hod?
Final
izemet hodhelpstoperfor
m cl
eanupoperat
ionsonther
esourceswhi
chare
notcur rent
lyused.Fi
nal
izemethodisprot
ect
ed,anditi
saccessi
bleonl
ythr
ough
thisclassorbyader i
vedclass.

19)Whatar
ethedi
ff
erentt
ypesofar
gument
s?
Aparameteri
sav ari
abl
eusedduringthedeclar
ati
onofthefuncti
onor
subr
outi
ne,andargumentsarepassedtothefunct
ionbody,anditshoul
dmat
ch
wit
htheparameterdefi
ned.Ther
earetwot y
pesofAr guments.

 CallbyValue–Val uepassedwillgetmodi f
iedonl
yinsidethef unct
ion,
and
i
treturnsthesamev al
uewhat everitispassedint
ot hefunction.
 CallbyReference–Valuepassedwi l
lgetmodifi
edinbot hinsideand
outsidethefunct
ionsanditret
urnst hesameordi f
ferentvalue.
20)Whati
sthesuperkey
wor
d?
Thesuperkeywor
disusedt oi
nvoketheoverr
iddenmethod,
whichover
ri
desone
ofi
tssupercl
assmethods.Thi
skeywordall
owst oaccessover
ri
ddenmethods
andal
sotoaccesshiddenmember softhesupercl
ass.
I
tal
sof
orwar
dsacal
lfr
om aconst
ruct
or,
toaconst
ruct
ori
nthesuper
class.

21)Whati
smet
hodov
err
idi
ng?
Methodov
er ri
dingi
safeaturethatall
owsasubcl asstoprovidethe
i
mplementati
onofamet hodt hatover
ridesinthemainclass.Itwil
lov
erri
det
he
i
mplementati
oni nt
hesuperclassbyprov i
dingthesamemet hodname, same
par
ameter
, andsameretur
nt ype.

22)Whati
sani
nter
face?
Aninter
faceisacol
l
ecti
onofanabstractmet
hod.Ift
heclassimplement
san
i
nterf
ace,itt
her
ebyi
nheri
tsal
ltheabstr
actmethodsofanint
erface.
Jav
ausesI
nter
facet
oimpl
ementmul
ti
plei
nher
it
ances.

23)Whati
sexcept
ionhandl
ing?
Anexcepti
onisanev entthatoccur
sduri
ngtheexecut
ionofaprogram.
Except
ionscanbeofanyt y
pe–Runt i
meexcepti
on,Er
rorexcept
ions.Those
except
ionsareadequatelyhandl
edthr
oughexcepti
onhandli
ngmechani sm l
i
ke
tr
y,cat
ch,andthrowkey words.

24)Whatar
etokens?
Acompilerr
ecognizesatoken,anditcannotbebr
okendownintocomponent
el
ements.Keywords,i
denti
fi
ers,const
ants,st
ri
ngl
it
eral
s,andoper
ator
sare
ex
amplesoft okens.
Evenpunctuati
onchar
act
ersarealsoconsi
der
edast
okens.Exampl
e:Br
acket
s,
Commas, Braces,
andPar
entheses.

25)Whatisthemai
ndi
ff
erencebet
weenov
erl
oadi
ngand
over
ri
ding?
Over
loadingi
sstati
cBi
nding,wher
easOv err
idi
ngisdynamicBi
ndi
ng.Ov
erl
oadi
ng
i
snothingbutthesamemet hodwi
thdiff
erentarguments,
andi
tmayormaynot
r
etur
nt heequalval
uei
nthesamecl assi
tself.
Overr
idingist
hesamemethodnameswi
ththesamear
gument
sandr
etur
nty
pes
associatedwi
tht
hecl
assandit
schi
ldcl
ass.

26)Whati
sthemai
ndi
ff
erencebet
weenacl
assandanobj
ect
?
Anobjecti
sani
nstanceofaclass.Object
sholdmult
ipl
einfor
mati
on,butcl
asses
don’
thaveanyi
nfor
mation.Defi
nit
ionofproper
ti
esandfuncti
onscanbedonein
cl
assandcanbeusedbyt heobject.
Acl
asscanhav
esub-
classes,
whi
l
eanobj
ectdoesn’
thav
esub-
obj
ect
s.

27)Whati
sanabst
ract
ion?
Abstracti
oni sausef ulf
eatureofOOPS, anditshowsonlythenecessarydetail
s
totheclientofanobj ect.Meaning,itshowsonl yrequi
reddetail
sforanobject
,
nottheinnerconst ruct
ors,ofanobj ect.Example–Wheny ouwantt oswit
chon
thetelev
ision, i
tisnotnecessarytoknowt heinnerci
rcui
tr
y/mechanism needed
toswitchont heTV.What everi
sr equir
edt oswitchonTVwi l
l beshownbyusi ng
anabst r
actcl ass.

28)Whatar
etheaccessmodi
fi
ers?
Accessmodifi
ersdeterminet
hescopeofthemet hodorvar
iabl
esthatcanbe
accessedfr
om othervari
ousobj
ect
sorclasses.Therear
efivet
ypesofaccess
modifi
ers,
andtheyareasf ol
l
ows:
 Pri
vate
 Prot
ected
 Publi
c
 Fr
iend
 Prot
ectedFr
iend

29)Whatar
eseal
edmodi
fi
ers?
Seal
edmodi f
ier
saretheaccessmodi
fier
swherethemethodscannoti
nheri
tit
.
Seal
edmodi f
ier
scanalsobeappli
edtoproper
ti
es,ev
ent
s,andmethods.Thi
s
modif
iercannotbeusedtostat
icmembers.

30)Howcanwecal
lthebasemet
hodwi
thoutcr
eat
ingan
i
nstance?
Yes,i
tispossi
blet
ocall
thebasemet
hodwi
thoutcr
eat
ingani
nst
ance.Andt
hat
methodshouldbe“St
ati
cmethod.

Doi
ngI
nher
it
ancef
rom t
hatcl
ass.
-UseBaseKey
wor
dfr
om ader
ivedcl
ass.

31)Whati
sthedi
ff
erencebet
weennewandov
err
ide?
Thenewmodi f
ieri
nstr
uctsthecompil
ert
ousethenewimplementat
ioni
nst
ead
oft
hebasecl assfuncti
on.Whereas,
Over
ridemodi
fi
erhel
pstooverr
idet
hebase
cl
assfunct
ion.

32)Whatar
ethev
ari
oust
ypesofconst
ruct
ors?
Ther
ear
ethr
eet
ypesofconst
ruct
ors:
– Def
aul
tConst
ruct
or–Wi
thnopar
amet
ers.
– Par
ametr
icConstr
uct
or–Wit
hParameters.Cr
eat
eanewi
nst
anceofacl
ass
andal
sopassi
ngargument
ssi
mult
aneously
.
– CopyConst
ruct
or–Whi
chcr
eat
esanewobj
ectasacopyofanexi
sti
ngobj
ect
.
33)Whati
sear
lyandl
ateBi
ndi
ng?
Earl
ybindingrefer
stotheassi
gnmentofval
uestovari
abl
esduri
ngdesi
gnti
me,
whereaslateBindi
ngrefer
stotheassi
gnmentofval
uestovar
iabl
esdur
ingr
un
ti
me.

34)Whati
s‘t
his’
poi
nter
?
THISpointerr
eferstothecurr
entobj
ectofaclass.THISkeywor
disusedasa
point
erwhichdiffer
enti
atesbet
weenthecurr
entobjectwit
htheglobal
obj
ect
.It
ref
erstothecurrentobject
.

35)Whati
sthedi
ff
erencebet
weenst
ruct
ureandacl
ass?
Thedef aul
taccesstypeofaSt r
uctur
eispublic,
butclassaccesst ypeispr i
vate.
Ast r
ucturei
susedf orgroupi
ngdata,whereasacl asscanbeusedf orgrouping
dataandmet hods.Struct
uresareexcl
usivel
yusedf ordat
a, anditdoesn’trequir
e
stri
ctvali
dati
on,butcl
assesareusedt oencapsulateandinherentdata,which
requir
esstri
ctvali
dati
on.

36)Whati
sthedef
aul
taccessmodi
fi
eri
nacl
ass?
Thedef
aul
taccessmodi
fierofacl
assi
sInt
ernal
andt
hedef
aul
taccessmodi
fi
er
ofacl
assmemberisPri
vate.

37)Whati
sapur
evi
rt
ualf
unct
ion?
Apur evir
tual
functi
onisafuncti
onwhichcanbeover
riddeni
ntheder
ivedcl
ass
butcannotbedefined.Avi
rtual
funct
ioncanbedecl
aredasPurebyusi
ngthe
operator=0.
Exampl
e–
Vi
rt
ual
voi
dfunct
ion1(
)//Vi
rt
ual
,Notpur
e
Vi
rt
ual
voi
dfunct
ion2(
)=0/
/Pur
evi
rt
ual

38)Whatar
eal
ltheoper
ator
sthatcannotbeov
erl
oaded?
Fol
l
owi
ngar
etheoper
ator
sthatcannotbeov
erl
oaded-
.

1.ScopeResol
uti
on(:
:)
2.MemberSelect
ion(
.)
3.Memberselect
iont
hroughapoi
ntert
ofunct
ion(
.*)

39)Whati
sdy
nami
corr
unt
imepol
ymor
phi
sm?
DynamicorRunt imepolymorphi
sm isalsoknownasmethodoverr
idi
nginwhich
callt
oanov err
iddenfunct
ionisr
esolvedduringr
unti
me,notatt
hecompilet
ime.
Itmeanshav i
ngt woormor emethodswiththesamename,samesignat
urebut
withdif
fer
entimpl ement
ati
on.

40)Dower
equi
reapar
amet
erf
orconst
ruct
ors?
No,
wedonotr
equi
reapar
amet
erf
orconst
ruct
ors.

41)Whati
sacopyconst
ruct
or?
Thi
sisaspeci
alconst
ruct
orf
orcreat
inganewobjectasacopyofanexisti
ng
obj
ect
.Ther
ewi l
lal
waysbeonlyonecopyconst
ruct
orthatcanbeei
therdef
ined
byt
heuserorthesyst
em.

42)Whatdoest
hekey
wor
dvi
rt
ualr
epr
esent
edi
nthemet
hod
defi
nit
ion?
I
tmeanswecanov
err
idet
hemet
hod.
43)Whet
herst
ati
cmet
hodcanusenonst
ati
cmember
s?
Fal
se.

44)Whatar
eabasecl
ass,
subcl
ass,
andsuper
class?
Thebasecl
assi
sthemostgener
ali
zedcl
ass,
andi
tissai
dtobear
ootcl
ass.
ASubcl
assi
sacl
asst
hati
nher
it
sfr
om oneormor
ebasecl
asses.
Thesuper
classi
sthepar
entcl
assf
rom whi
chanot
hercl
assi
nher
it
s.

45)Whati
sst
ati
canddy
nami
cBi
ndi
ng?
Bindi
ngisnothi
ngbuttheassoci
ati
onofanamewit
ht hecl
ass.St
ati
cBi
ndingi
s
abindingi
nwhichnamecanbeassociatedwi
tht
heclassduri
ngcompil
ati
on
ti
me, andi
tisal
socal
ledasearlyBi
ndi
ng.
DynamicBindi
ngi
sabindi
ngi
nwhichnamecanbeassoci
atedwi
tht
hecl
ass
duri
ngexecuti
ont
ime,
anditi
sal
socall
edasLat
eBindi
ng.

46)Howmanyi
nst
ancescanbecr
eat
edf
oranabst
ractcl
ass?
Zer
oinst
anceswill
becreat
edforanabst
ractcl
ass.I
not
herwor
ds,
youcannot
cr
eateaninst
anceofanAbstr
actCl
ass.

47)Whi
chkey
wor
dcanbeusedf
orov
erl
oadi
ng?
Oper
atorkey
wor
disusedf
orov
erl
oadi
ng.

48)Whati
sthedef
aul
taccessspeci
fi
eri
nacl
assdef
ini
ti
on?
Pr
ivat
eaccessspeci
fi
eri
susedi
nacl
assdef
ini
ti
on.
49)Whi
chOOPSconcepti
susedasar
eusemechani
sm?
I
nher
it
ancei
stheOOPSconceptt
hatcanbeusedasar
eusemechani
sm.

50)Whi
chOOPSconceptexposesonlyt
henecessar
y
i
nfor
mati
ontot
hecall
ingfunct
ions?
Encapsul
ati
on

Thanks

You might also like