Java Question and Answer
Java Question and Answer
Java Question and Answer
aMCQ(
Mul
ti
pleChoi
ceQuest
ionsandAnswer
)
1.Thesmal
l
esti
ntegert
ypei
s__
___
___andi
tssi
zei
s__
___
___
_bi
ts.
A.shor
t,16
B.shor
t,16
C.by
te,
8
D.shor
t,8
Answer
:by
te,
8
2.Si
zeoff
loatanddoubl
einJav
ais_
___
___
__
A.32and32
B.32and64
C.64and64
D.64and32
Answer
:32and64
3.Whi
choft
hef
oll
owi
ngaut
omat
ict
ypeconv
ersi
onwi
l
lbepossi
ble?
A.i
ntt
olong
B.by
tet
oint
C.shor
ttoi
nt
D.l
ongt
oint
Answer
:intt
olong
4.Aut
omat
ict
ypeconv
ersi
oni
nJav
atakespl
acewhen_
___
___
___
_
A.Twot
ypear
ecompat
ibl
eandsi
zeofdest
inat
iont
ypei
slar
gert
hansour
cet
ype
B.Twot
ypear
ecompat
ibl
eandsi
zeofdest
inat
iont
ypei
sequal
ofsour
cet
ype
C.Twot
ypear
ecompat
ibl
eandsi
zeofdest
inat
iont
ypei
sshor
tert
hansour
cet
ype
D.Al
loft
heabov
e
Answer
:Twot
ypear
ecompat
ibl
eandsi
zeofdest
inat
iont
ypei
slar
gert
hansour
cet
ype
5.I
nJav
a,t
hewor
dtr
uei
s__
___
___
___
___
__
A.ABool
eanl
i
ter
al
B.AJav
akey
wor
d
C.Sameasv
alue1
D.Sameasv
alue0
Answer
:ABool
eanl
i
ter
al
6.Si
zeofi
nti
nJav
ais_
___
___
___
_
A.64bi
t
B.16bi
t
C.32bi
t
D.Dependsonexecut
ionenv
ironment
Answer
:32bi
t
7.I
nJav
aar
ray
sar
e__
___
___
_
A.pr
imi
ti
vedat
aty
pe
B.obj
ect
s
C.obj
ectr
efer
ences
D.None
Answer
:obj
ect
s
8.Sel
ectf
rom amongt
hef
oll
owi
ngchar
act
erescapecodewhi
chi
snotav
ail
abl
einJav
a.
A.\
t
B.\
r
C.\
a
D.\
\
Answer
:\a
9.Wheny
oupassanar
rayt
oamet
hod,
themet
hodr
ecei
ves_
___
___
_
A.Ther
efer
enceoft
hear
ray
B.Acopyoft
hef
ir
stel
ement
C.Acopyoft
hear
ray
D.Thel
engt
hoft
hear
ray
Answer
:Ther
efer
enceoft
hear
ray
10.Whi
choneoft
hef
oll
owi
ngi
sav
ali
dst
atement
?
A.char
[]c=newchar
[5]
;
B.char
[]c=newchar
();
C.char
[]c=newchar
(4)
;
D.char
[]c=newchar
[]
;
Answer
:char
[]c=newchar
[5]
;
11.I
nJav
aby
te,
shor
t,i
ntandl
ongal
loft
hesear
e__
___
___
___
A.unsi
gned
B.si
gned
C.Bot
hA&B
D.None
Answer
:si
gned
12.Whi
choft
hef
oll
owi
ngf
orl
oopswi
l
lbeani
nfi
nit
eloop?
A.f
or(
i=0;
i<1;
i–)
B.f
or(
;
C.f
or(
i=0;
;i++)
D.Al
loft
heabov
e
Answer
:Al
loft
heabov
e
13.Theobj
ecti
scr
eat
edwi
thnewkey
wor
d__
___
___
___
A.AtCompi
l
e-t
ime
B.Dependsont
hecode
C.Atr
un-
ti
me
D.Noneoft
hese
Answer
:Atr
un-
ti
me
14.Apackagei
sacol
l
ect
ionof
___
___
___
_
A.I
nter
faces
B.Cl
asses
C.Edi
ti
ngt
ool
s
D.Cl
assesandI
nter
faces
Answer
:Cl
assesandI
nter
faces
15.Howmanypr
imi
ti
vedat
aty
pesar
ether
einJav
a?
A.7
B.8
C.6
D.9
Answer
:8
16.Jav
aisa_
___
___
__l
anguage.
A.st
rongl
yty
ped
B.weakl
yty
ped
C.moder
atet
yped
D.None
Answer
:st
rongl
yty
ped
17.Amet hodwi
thi
naclassi
sonlyaccessibl
ebycl
assesthatar
edefinedwi
thinthesame
packageasthecl
assofthemet
hod.Whi choneoft
hefoll
owingisusedtoenforcesuch
rest
ri
cti
on?
A.Decl
aret
hemet
hodwi
tht
hekey
wor
dpr
ivat
e
B.Decl
aret
hemet
hodwi
tht
hekey
wor
dpubl
i
c
C.Decl
aret
hemet
hodwi
tht
hekey
wor
dpr
otect
ed
D.Donotdecl
aret
hemet
hodwi
thanyaccessi
bil
i
tymodi
fi
ers
Answer
:Donotdecl
aret
hemet
hodwi
thanyaccessi
bil
i
tymodi
fi
ers
18.Namet hekey
wordthatmakesav
ari
abl
ebel
ongt
oacl
ass,
rat
hert
hanbei
ngdef
inedf
or
eachinst
anceofthecl
ass.
A.abst
ract
B.st
ati
c
C.f
inal
D.nat
ive
Answer
:st
ati
c
19.t
oSt
ri
ng(
)met
hodi
sdef
inedi
n__
___
___
__
A.j
ava.
lang
B.j
ava.
lang.
uti
l
C.j
ava.
lang.
Str
ing
D.j
ava.
lang.
Obj
ect
Answer
:jav
a.l
ang.
Obj
ect
20.TheSt
ri
ngmet
hodcompar
eTo(
)ret
urns
A.t
rue
B.f
alse
C.ani
ntv
alue
D.1
Answer
:ani
ntv
alue
21.Thecl
assst
ri
ngbel
ongst
o__
___
___package.
A.j
ava.
appl
et
B.j
ava.
awt
C.j
ava.
lang
D.j
ava.
str
ing
Answer
:jav
a.l
ang
22.HowmanyConst
ruct
orSt
ri
ngcl
asshav
e?
A.7
B.13
C.2
D.5
Answer
:13
23.Whatwi
l
lbet
her
etur
nty
peofamet
hodt
hatnotr
etur
nsanyv
alue?
A.Char
B.doubl
e
C.v
oid
D.i
nt
Answer
:voi
d
24.Whati
sMat
h.f
loor
(3.
6)?
A.4
B.3
C.3.
0
D.4.
0
Answer
:3.
0
25.Whi
choft
hef
oll
owi
ngopt
ionsi
sthebestf
orgener
ati
ngr
andom i
nteger0or1?
A.(
int
)Mat
h.r
andom(
)
B.(
int
)Mat
h.r
andom(
)+1
C.(
int
)(Mat
h.r
andom(
)+0.
5)
D.(
int
)(Mat
h.r
andom(
)+0.
2)
Answer
:(i
nt)
(Mat
h.r
andom(
)+0.
5)
26.I
nwhichareaofmemor
y,t
hesy
stem st
orespar
amet
ersandl
ocal
var
iabl
eswhenev
era
methodi
sinvoked?
A.Ar
ray
B.Heap
C.St
orageAr
ea
D.St
ack
Answer
:St
ack
27.Thef
inal
i
ze(
)met
hodi
scal
l
edj
ustpr
iort
o__
___
___
___
_
A.Anobj
ect
,var
iabl
eormet
hodgoesoutofscope
B.Bef
oregar
bagecol
l
ect
ion
C.Anobj
ectorv
ari
abl
egoesoutofscope
D.Av
ari
abl
egoesoutofscope
Answer
:Bef
oregar
bagecol
l
ect
ion
28.Thei
mpl
i
citr
etur
nty
peofaconst
ruct
ori
s__
___
___
__
A.Ther
eisnor
etur
nty
pe
B.v
oid
C.Acl
assobj
ecti
nwhi
chi
tisdef
ined
D.None
Answer
:Acl
assobj
ecti
nwhi
chi
tisdef
ined
29.Thev
ari
abl
esdecl
aredi
nacl
assf
ort
heuseofal
lmet
hodsoft
hecl
assar
ecal
l
ed_
___
___
_
A.i
nst
ancev
ari
abl
es
B.obj
ect
s
C.r
efer
encev
ari
abl
es
D.None
Answer
:inst
ancev
ari
abl
es
30.Whi
choft
hemodi
fi
ercan’
tbeusedf
orconst
ruct
ors?
A.publ
i
c
B.st
ati
c
C.pr
ivat
e
D.pr
otect
ed
Answer
:st
at