Java MCQ

You might also like

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

JAVA MCQS

1.Whoi nventedJavaProgr
ammi
ng?
a)Guidov anRossum
b)JamesGosl i
ng
c)DennisRi t
chie
d)BjarneStroustr
up
Answer
:b

2.Whichst
atementist
rueaboutJav a?
a)Javai
sasequence-dependentprogramminglanguage
b)Javai
sacodedependentpr ogrammi ngl
anguage
c)Javai
saplatf
orm-dependentprogramminglanguage
d)Javai
saplatf
orm-independentprogramminglanguage

Answer
:d

3.Whatist
her
etur
nty
peofamet
hodt
hatdoesnotr
etur
nanyv
alue?
a)i
nt
b)fl
oat
c)voi
d
d)doubl
e

Answer
:c

4.Whatist heprocessofdefi
ningmor
ethanonemet
hodi
nacl
ass
di
ffer
ent
iatedbymet hodsignat
ure?
a)Funct
ionov er
ridi
ng
b)Funct
ionov er
loading
c)Funct
iondoubling
d)Noneoft hement i
oned

Answer
:b

5.Whi choftheseaccessspeci
fi
erscanbeusedf
orani
nter
face?
a)Public
b)Protected
c)pr
ivate
d)Allofthementioned

Answer
:a

6.Whichofthesei
sani ncor
rectar
raydecl
arat
ion?
a)i
ntarr[
]=newint[
5]
b)i
nt[]ar
r=newi nt
[5]
c)i
ntarr[
]=newint[
5]
d)i
ntarr[
]=int[
5]new
Answer
:d

7.Thesmal lesti
ntegert
ypei
s__
___
___
___
___
_andi
tssi
zei
s__
___
___bi
ts.
a)short,
8
b)byte,
8
c)
shor t,
16
d)byte,
16

ANSWER:
b

8.Thef
oll
owi
ngSy
ntaxi
susedf
or?

cl
assSubcl
ass-
nameext
endsSuper
class-
name
{
//
methodsandfi
elds
}

a.
 Poly
mor phi
sm
b.
 Encapsulat
ion
c.
 I
nherit
ance
d.
 Noneoft heabov
e

ANSWER:
Inher
it
ance

9.
Whi
chconst
ruct
orcr
eat
esanempt
yst
ri
ngbuf
ferwi
tht
hespeci
fi
edcapaci
tyasl
engt
h.

a.
 St
ri
ngBuf
fer
()
b.
 St
ri
ngBuf
fer
(St
ri
ngstr)
c.
 St
ri
ngBuf
fer
(i
ntcapaci
ty)
d.
 Noneoft
heabove

ANSWER:
Str
ingBuf
fer
(i
ntcapaci
ty)

10.Apackagecanber
enamedwi
thoutr
enami
ngt
hedi
rect
oryi
nwhi
cht
hecl
assesar
est
ored.
a.
 True
b.
 False

ANSWER:
Fal
se
11.
Byov
err
idi
ngt
het
oSt
ri
ng(
)met
hodoft
heObj
ectcl
ass,
wecanr
etur
nval
uesoft
heobj
ect
,sowe
a.
 True
b.
 False

ANSWER:
True
12.Whi
chst
atementpr
ovi
desaneasywayt
odi
spat
chexecut
iont
odi
ff
erentpar
tsofy
ourcodebas

a.
 I
f
b.
 Switch
c.
 Nested-
if
d.
 i
f-
else-i
f

ANSWER:Swi
tch

13.Packagesar
eusedf
ordi
str
ibut
ingacol
l
ect
ionofr
eusabl
ecl
asses,
usual
l
yinaf
ormatknownas

a.
 True
b.
 False

ANSWER:Tr
ue

14.Packagesar
eusedf
ordi
str
ibut
ingacol
l
ect
ionofr
eusabl
ecl
asses,
usual
l
yinaf
ormatknownas
a.
 True
b.
 False

ANSWER:Tr
ue

15.Whi
chi
sasuper
classofal
lex
cept
ioncl
asses?
a.
 Throwable
b.
 Excepti
on
c.
 Runti
meExcept
ion
d.
 I
OException

ANSWER:Thr
owabl
e

16.Whati
sther
angeoft
hei
ntdat
aty
pe?
a.
 –2,147,483,648t
o2,147,483,647
b.
 -
2,147,483,647to2,
147,483,648
c.
 -
32,
768t
o32,
767
d.
 -
32,
767t
o32,
768

ANSWER:–2,
147,
483,
648t
o2,
147,
483,
647

17.Jav
aVi
rt
ual
Machi
nei
spl
atf
ormi
ndependent
.
a.
 True
b.
 False

ANSWER:Fal
se

18.Whi
chi
samechani
sm wher
eoneobj
ectacqui
resal
lthepr
oper
ti
esandbehav
ior
soft
hepar
ent
a.
 I
nherit
ance
b.
 Encapsulat
ion
c.
 Poly
mor phi
sm
d.
 Noneoft heabov
e

ANSWER:I
nher
it
ance

19.Whi
chi
sat
echni
quei
nJav
ainwhi
chacl
asscanhav
eanynumberofconst
ruct
orst
hatdi
ff
eri
n
a.
 Constr
uct
oroverloadi
ng
b.
 Methodoverl
oading
c.
 Operat
orover
loading
d.
 Noneoftheabove

ANSWER:Const
ruct
orov
erl
oadi
ng

20.Nest
edi
nter
facemustbepubl
i
cifi
tisdecl
aredout
sidet
hei
nter
facebuti
tcannothav
eanyacc
cl
ass.
a.
 True
b.
 False

ANSWER:Fal
se
21.Whi
chkey
wor
disusedf
ort
hebl
ockt
ohandl
etheexcept
ionsgener
atedbyt
rybl
ock?
a.
 Cat ch
b.
 Final
c.
 throw
d.
 try
ANSWER:Cat
ch
22.Underwhi
chpackagei
sthest
ri
ngcl
assencapsul
ated?
a.
 j
ava.
lang
b.
 j
ava.
util
c.
 j
ava.
io
d.
 j
ava.
awt

ANSWER:j
ava.
lang
23.Whatt
ypeofconst
ruct
ori
susedt
opr
ovi
dedi
ff
erentv
aluest
othedi
sti
nctobj
ect
s?
a.
 Defaul
tconstruct
or
b.
 Parameteri
zedconst r
uctor
c.
 Overl
oadingconstructor
d.
 Noneoft heabove

ANSWER:Par
amet
eri
zedconst
ruct
or
24.Whatwi
llhappeni
fwecal
lther
un(
)met
hoddi
rect
lyi
nst
eadofcal
li
ngt
hest
art
()met
hod?
a. 
Eachthr
eadstar
tsinasepar
atecal
lst
ack.
b. 
Inv
oki
ngt her
un()met
hodfrom mai
nthread,
ther
un(
)met
hodgoesont
othecur
rentcal
lst
ackr
a
newcallst
ack.
c.
 BothA&B
d. 
Noneoftheabove

ANSWER:Bot
hA&B
25. 
Whi
chmet
hodwai
tsf
orat
hreadt
odi
e?
a.
 stop()
b.
 start
()
c.
 terminat
e()
d.
 j
oin()

ANSWER:j
oin(
)
26.Acl
assi
sdecl
aredi
nsi
deacl
assbutout
sideamet
hodi
tisknownas_
___
___
_.
a.
 Anony
mousI
nnercl
ass
b.
 MemberI nnerclass
c.
 LocalI
nnerclass
d.
 Stat
icnestedclass

ANSWER:MemberI
nnercl
ass
27. 
Anabst
ractcl
asshasnousewheni
tisext
endedbysomeot
hercl
ass.
a.
 True
b.
 False

ANSWER:True
28.Whati
stheadv
ant
ageofMet
hodOv
erl
oadi
ng?
a.
 Methodover
loadi
ngi
ncreasesthereadabil
it
yoft heprogr
am
b.
 Methodover
loadi
ngdoesnotincr
easest hereadabil
it
yoftheprogr
am
c.
 Methodover
loadi
ngdoesnotincr
easesther el
iabil
it
yofthepr
ogram
d.
 Noneoftheabove

ANSWER:Met hodov erl


oadi
ngi
ncr
easesthereadabi
li
tyoft
hepr ogram
29.I
fasubclasshast hesamemethodasdeclar
edintheparentclassiti
sknownas_
___
__.
a.
 Methodoverr
iding
b.
 Methodoverl
oading
c.
 Constr
uct
orov erl
oadi
ng
d.
 Noneoftheabov e

ANSWER:Met
hodov
err
idi
ng

30.  
Ift
her
eisnoconst
ruct
ori
nacl
ass,
compi
leraut
omat
ical
lycr
eat
esadef
aul
tconst
ruct
or
a.
 True
b.
 False

ANSWER:Tr
ue

31.Whatar ethemainsubclassesoft
heExcept
ioncl
ass?
a.
 I
OExceptionclass
b.
 RuntimeExcepti
onClass
cClassCast
Exception
d.
 BothA&B
 
ANSWER:Bot
hA&B

32.Whi
chpackagei
susedf
orGUI
?
a.
 j
ava.
lang
b.
 j
ava.
awt
c.
 j
ava.
lang.
ref
d.
 j
ava.
io

ANSWER:j
ava.
awt
33. 
Whi
cht
ypeofpol
ymor
phi
sm i
snot
hingbutt
hemet
hodov
erl
oadi
ngi
njav
a?
a.
 Compilet
imepolymorphi
sm
b.
 Runti
mepolymorphi
sm
c.
 St
aticpol
ymorphi
sm
d.
 BothA&C
 
ANSWER:Bot
hA&C
34.Except
ionHandl
ingi
samechani
sm t
ohandl
erunt
imeer
ror
s
a.
 True
b.
 False
 
ANSWER:Tr
ue
35.Whi
chi
nher
it
ancei
snotsuppor
tedi
njav
a?
a.
 Singleinheri
tance
b.
 Mul ti
ple
c.
 Mul ti
l
evelinheri
tance
d.
 Hy bri
d
e.
 Jav asupportsalloft
heabov
e
 
ANSWER:Jav
asuppor
tsal
loft
heabov
e

36.Wher
ear
ethesef
ivekey
wor
dst
ry,
cat
ch,
final
ly
,thr
ow,
andt
hrowsusedi
n?
a.
 Except
ionHandl
ing
b.
 Str
ingHandl
ing
c.
 EventHandl
i
ng
d.
 Noneoftheabove

ANSWER:Except
ionHandl
ing
37.Whichofthesef
unct
ionsi
scal
l
edt
odi
spl
ayt
heout
putofanappl
et?
a)di
splay()
b)pai
nt()
c)di
splayAppl
et(
)
d)Pri
ntApplet
()

Answer
:b
38.Whichoft hesemet
hodscanbeusedt
oout
putast
ri
ngi
nanappl
et?
a)di
splay()
b)print
()
c)drawStri
ng()
d)tr
ansient(
)

Answer
:c
39.Whichoft hesemet
hodsi
sapar
tofAbst
ractWi
ndowTool
ki
t(AWT)?
a)di
splay()
b)paint
()
c)drawStri
ng()
d)tr
ansient(
)

Answer
:b

40. 
Aftercompi
l
ati
ont
heJav
apr
ogi
scov
etedt
o-
a.Byt
e
b.Javafi
le
c.Byt
ecode
d.Byt
ebasic

Answer
:c
41. 
۸ 
oper
atori
s–
a.Bi
twi
secomplement
b.Bi
twi
seOR
c.Bi
twi
seXOR
d.Bi
twi
seAND
Answer
:d
42.Cor
rectsy ntaxforLoopis-
a.For(
ini
tialstatement,ter
minationbond,
incr
ementi
nst
ruct
ion)
b.For(
ini
ti
al statement,i
ncrementstat
ement)
c.For(
I=0, C++)
d.For(
terminationconditi
on,i
ncrement)
Answer
:a
43. I
nwhi chst
atementt
hel
oopsar
eski
ppedandt
henexti
ter
ati
onst
art
s.
a.Break
b.Continue
c.Got o
d.Label
Answer
:b
44.Vari
ablethatisdecl
aredout
sidet
hemet
hoddef
ini
ti
on.
a.Clani
nstant
b.Clanvari
able
c.I
nstancev ar
iable
d.Localvar
iable

Answer
:c
45.Variabl
ethati
sdef
inedwi
tht
hemet
hod.
a.Local
b.Global
c.Clan
d.I
nst
ance

Answer
:a
46. 
Somenamef or
emor
ethatonecanbei
mpl
ement
edby
-
a.Overl
oading
b.Overr
idi
ng
c.Overl
appi
ng
d.Overexi
sting
Answer
:a
47.Codet hatthr
owsanexcept
ion
a.catchblock
b.try/cat
chblock
c.tryblock
d.throwblock

Answer
:c

48.Anotheropt
iont
ouset
ry/
cat
chbl
ocki
s
a.throws
b.final
ly
c.fi
nal
d.catch

Answer
:b

49.Whenmul
ti
pleexcept
ionsi
stobet
hrownwhi
chcl
ausei
sused.
a.fi
nall
y
b.fi
nal
c.thr
ows
d.catch

Answer
:c

50.Howcanwecr
eat
eonobj
ofacl
ass
a.newobject
b.new
c.creat
e
d.drew

Answer
:b
51.Alldat
ainj
avai
swr
it
tenandr
ead
a.str
ings
b.extends
c.str
eams
d.str
imps

Answer
:c

52.Standardinputst
ream orast
ream t
hatr
espondst
okey
boar
dinput
a.system out
b.system err
or
c.system in
d.system

Answer
:c

53.
Whi
char
ethecommonsecur
it
yrest
ri
cti
onsi
nappl
ets?

a.
 Applet
scan'tl
oadli
brari
esordefi
nenati
vemet
hods
b.
 Anappletcan'
treadeverysy
stem pr
opert
y
c.
 Applet
scanplaysounds
d.
 BothA&B
 
ANSWER:
Bot
hA&B

54.Appl
etwor
ksatcl
ientsi
desol
essr
esponset
ime.
a.
 True
b.
 False
 
ANSWER:
True
55.TheAPPLETt
agi
susedt
ost
artanappl
etf
rom bot
hanHTMLdocumentandf
rom anappl
etv

a.
 True
b.
 False
 
ANSWER:
True
56.Whi
chmet
hodi
sfi
rstCal
ledf
oranyappl
etwheni
tst
art
sit
sexecut
ion?

a.
 voi
dini
t(
)
b.
 voi
ddest
roy
()
c.
 bool
eani
sActi
ve(
)
d.
 Noneoft
heabove
 
Answer 
Expl
anat
ion 
ANSWER:
voi
dini
t(
)

ANSWER:
voi
dini
t(
)

57.Whenanappl etbegi
ns,
inwhi
chsequencewi
llt
heAWTcal
lthemet
hods?
a. 
i
nit
(),
pai
nt(
),
start
()
b.
 Start
(),
paint
(),
init
()
c.
 i
ntit(
),
start
(),
paint(
)
d.
 paint(
),
start
(),
ini
t()
 
ANSWER:
int
it
(),
star
t()
,pai
nt(
)
58.Al
lAppl
etsmusti
mpor
tjav
a.appl
etandj
ava.
awt
.
a.
 True
b.
 False
 
ANSWER:
True
59.Whi
chist
hecor
rectorderofl
ifecyclei
nanappl et
?
a.
 Appl
eti
sst
art
ed,
i
nit
ial
ized,
pai
nted,destr
oyed,
stopped
b.
 Appl
eti
spainted,st
arted,st
opped,
init
il
aized,
dest
royed
c.
 Appl
eti
sinit
ial
ized,
started,
pai
nted,st
opped,dest
roy
ed
d.
 Noneoftheabov e
 
ANSWER:Appl
eti
sini
ti
ali
zed,
star
ted,pai
nted,
stopped,
dest
roy
ed
Whi
60. chisaspeci
alty
peofpr ogram thati
sembeddedi nthewebpaget
ogener
atet
hedy
nami
c
a.
 Package
b.
 Applet
c.
 Browser
d.
 Noneoftheabov
e
 
Answer 
Expl
anat
ion 
ANSWER:
Appl
et
ANSWER:
Appl
et

61.Whati
susedt
orunanAppl
et?
a.
 Anhtmlf
il
e
b.
 AnAppl
etVi
ewert
ool
(f
ort
est
ingpur
pose)
c.
 Bot
hA&B
d.
 Noneoft
heabove

ANSWER:
Bot
hA&B
62.Whi
chi
saspeci
alt
ypeofpr
ogr
am t
hati
sembeddedi
nthewebpaget
ogener
atet
hedy
nami
c
-a.
 Package
b.
 Appl
et
c.
 Br
owser
d.
 Noneoft
heabov
e
 
ANSWER:
Appl
et

Whi
63. chappl
etj
ava.
awt
.componentcl
asspr
ovi
dest
hel
if
ecy
clemet
hod?
a.
 publ
icv
oidpaint(
Graphi
csg)
b.
 publ
icvoi
ddestroy(
)
c.
 publ
i
cvoidstop()
d.
 publ
icvoi
dini
t()
 
ANSWER:
publ
icv
oidpai
nt(
Graphi
csg)
64.Whichi
sinvokedaft
ert
hei
nit
()met
hodorbr
owseri
smaxi
mized?
-a. 
publ
icv
oidstart
()
b.
 publ
i
cvoidpaint
(Graphi
csg)
c.
 Publ
icv
oidstop()
d.
 Publ
icvoi
dini
t()
 
ANSWER:
publ
icv
oidst
art
()
65.Appl
etr
unsi
nsi
det
hebr
owserandwor
ksatcl
ientsi
de

a.
 True
b.
 False
 
Answer 
Expl
anat
ion 
ANSWER:
True

ANSWER:
True

.
 

You might also like