Anda di halaman 1dari 13

1.

Whichdeclarationofthemainmethodbelowwouldallowaclasstobestartedasastandalone

program.Selecttheonecorrectanswer.
A. publicstaticintmain(charargs[])
B. publicstaticvoidmain(Stringargs[])
C. publicstaticvoidMAIN(Stringargs[])
D. publicstaticvoidmain(Stringargs)
E. publicstaticvoidmain(charargs[])
2. Whatallgetsprintedwhenthefollowingcodeiscompiledandrun?Selectthethreecorrect
answers.
publicclassxyz{
publicstaticvoidmain(Stringargs[]){
for(inti=0i<2i++){
for(intj=2j>=0j){
if(i==j)break
System.out.println("i="+i+"j="+j)
}
}
}
}

i=0j=0
i=0j=1
i=0j=2
i=1j=0
i=1j=1
i=1j=2
i=2j=0
i=2j=1
i=2j=2
3. Whatgetsprintedwhenthefollowingcodeiscompiledandrunwiththefollowingcommand
javatest2
Selecttheonecorrectanswer.
A.
B.
C.
D.
E.
F.
G.
H.
I.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
IntegerintObj=Integer.valueOf(args[args.length1])
inti=intObj.intValue()
if(args.length>1)
System.out.println(i)
if(args.length>0)
System.out.println(i1)
else
System.out.println(i2)
}
}

test
test1
0
1
2
4. InJavatechnologywhatexpressioncanbeusedtorepresentnumberofelementsinanarray
namedarr?
5. Howwouldthenumber5berepresentedinhexusinguptofourcharacters.
6. WhichofthefollowingisaJavakeyword.Selectthefourcorrectanswers.
A. extern
B. synchronized
C. volatile
D. friend
E. friendly
F. transient
G. this
H. then
7. Isthefollowingstatementtrueorfalse.Theconstructorofaclassmustnothaveareturntype.
A. true
B. false
8. WhatisthenumberofbytesusedbyJavaprimitivelong.Selecttheonecorrectanswer.
A. Thenumberofbytesiscompilerdependent.
B. 2
C. 4
D. 8
E. 64
9. Whatisreturnedwhenthemethodsubstring(2,4)isinvokedonthestring"example"?Include
theanswerinquotesastheresultisoftypeString.
10. Whichofthefollowingiscorrect?Selectthetwocorrectanswers.
A. Thenativekeywordindicatesthatthemethodisimplementedinanotherlanguagelike
C/C++.
B. TheonlystatementsthatcanappearbeforeanimportstatementinaJavafileare
comments.
C. Themethoddefinitionsinsideinterfacesarepublicandabstract.Theycannotbeprivate
orprotected.
D. Aclassconstructormayhavepublicorprotectedkeywordbeforethem,nothingelse.
11. Whatistheresultofevaluatingtheexpression14^23.Selecttheonecorrectanswer.
A. 25
B. 37
C. 6
D. 31
E. 17
F. 9
G. 24
A.
B.
C.
D.
E.

12. Whichofthefollowingaretrue.Selecttheonecorrectanswers.
A. &&operatorisusedforshortcircuitedlogicalAND.
B. ~operatoristhebitwiseXORoperator.
C. |operatorisusedtoperformbitwiseORandalsoshortcircuitedlogicalOR.
D. TheunsignedrightshiftoperatorinJavais>>.
13. Nametheaccessmodifierwhichwhenusedwithamethod,makesitavailabletoalltheclasses

inthesamepackageandtoallthesubclassesoftheclass.
14. Whichofthefollowingistrue.Selectthetwocorrectanswers.
A. Aclassthatisabstractmaynotbeinstantiated.
B. Thefinalkeywordindicatesthatthebodyofamethodistobefoundelsewhere.The

codeiswritteninnonJavalanguage,typicallyinC/C++.
C. Astaticvariableindicatesthereisonlyonecopyofthatvariable.
D. Amethoddefinedasprivateindicatesthatitisaccessibletoallotherclassesinthesame
package.
15. Whatallgetsprintedwhenthefollowingprogramiscompiledandrun.Selectthetwocorrect
answers.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti,j=1
i=(j>1)?2:1
switch(i){
case0:System.out.println(0)break
case1:System.out.println(1)
case2:System.out.println(2)break
case3:System.out.println(3)break
}
}
}

0
1
2
3
16. Whatallgetsprintedwhenthefollowingprogramiscompiledandrun.Selecttheonecorrect
answer.
A.
B.
C.
D.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti=0,j=2
do{
i=++i
j
}while(j>0)
System.out.println(i)

}
}

0
1
2
Theprogramdoesnotcompilebecauseofstatement"i=++i"
17. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthethreecorrect
answers.
A.
B.
C.
D.

18.
19. publicclasstest{
20. publicstaticvoidmain(Stringargs[]){
21. inti=1,j=1
22. try{
23. i++
24. j
25. if(i/j>1)
26. i++
27. }
28. catch(ArithmeticExceptione){
29. System.out.println(0)
30. }
31. catch(ArrayIndexOutOfBoundsExceptione){
32. System.out.println(1)
33. }
34. catch(Exceptione){
35. System.out.println(2)
36. }
37. finally{
38. System.out.println(3)
39. }
40. System.out.println(4)
41. }
42. }
43.
44.
A. 0
B. 1
C. 2
D. 3
E. 4
45. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthetwocorrectanswers.

publicclasstest{
publicstaticvoidmain(Stringargs[]){

inti=1,j=1
try{
i++
j
if(i==j)
i++
}
catch(ArithmeticExceptione){
System.out.println(0)
}
catch(ArrayIndexOutOfBoundsExceptione){
System.out.println(1)
}
catch(Exceptione){
System.out.println(2)
}
finally{
System.out.println(3)
}
System.out.println(4)
}
}

0
1
2
3
4
46. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthetwocorrectanswers.
A.
B.
C.
D.
E.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
Strings1="abc"
Strings2="abc"
if(s1==s2)
System.out.println(1)
else
System.out.println(2)
if(s1.equals(s2))
System.out.println(3)
else
System.out.println(4)
}
}

A. 1
B. 2

C. 3
D. 4
47. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Selectthetwocorrectanswers.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
Strings1="abc"
Strings2=newString("abc")
if(s1==s2)
System.out.println(1)
else
System.out.println(2)
if(s1.equals(s2))
System.out.println(3)
else
System.out.println(4)
}
}

1
2
3
4
48. Whichofthefollowingarelegalarraydeclarations.Selectthethreecorrectanswers.
A. inti[5][]
B. inti[][]
C. int[]i[]
D. inti[5][5]
E. int[][]a
49. Whatistherangeofvaluesthatcanbespecifiedforanint.Selecttheonecorrectanswer.
A. Therangeofvaluesiscompilerdependent.
B. 231to2311
C. 2311to231
D. 215to2151
E. 2151to215
50. Howcanyouensurethatthememoryallocatedbyanobjectisfreed.Selecttheonecorrect
answer.
A. Byinvokingthefreemethodontheobject.
B. Bycallingsystem.gc()method.
C. Bysettingallreferencestotheobjecttonewvalues(saynull).
D. Garbagecollectioncannotbeforced.TheprogrammercannotforcetheJVMtofree
thememoryusedbyanobject.
51. Whatgetsprintedwhenthefollowingcodeiscompiledandrun.Selecttheonecorrectanswer.
A.
B.
C.
D.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti=1
do{
i
}while(i>2)
System.out.println(i)
}
}

0
1
2
1
52. WhichoftheseisalegaldefinitionofamethodnamedmassumingitthrowsIOException,and
returnsvoid.Alsoassumethatthemethoddoesnottakeanyarguments.Selecttheonecorrect
answer.
A. voidm()throwsIOException{}
B. voidm()throwIOException{}
C. voidm(void)throwsIOException{}
D. m()throwsIOException{}
E. voidm(){}throwsIOException
53. WhichofthefollowingarelegalidentifiernamesinJava.Selectthetwocorrectanswers.
A. %abcd
B. $abcd
C. 1abcd
D. package
E. _a_long_name
54. Atwhatstageinthefollowingmethoddoestheobjectinitiallyreferencedbysbecomes
availableforgarbagecollection.Selecttheonecorrectanswer.
A.
B.
C.
D.

voidmethodX(){
Stringr=newString("abc")
Strings=newString("abc")
r=r+1//1
r=null//2
s=s+r//3
}//4

A.
B.
C.
D.

Beforestatementlabeled1
Beforestatementlabeled2
Beforestatementlabeled3
Beforestatementlabeled4

E. Never.
55. Strings=newString("xyz")

Assumingtheabovedeclaration,whichofthefollowingstatementswouldcompile.Selectthe
onecorrectanswer.
A. s=2*s
B. inti=s[0]
C. s=s+s
D. s=s>>2
E. Noneoftheabove.
56. WhichofthefollowingstatementsrelatedtoGarbageCollectionarecorrect.Selectthetwo
correctanswers.
A. Itispossibleforaprogramtofreememoryatagiventime.
B. GarbageCollectionfeatureofJavaensuresthattheprogramneverrunsoutofmemory.
C. ItispossibleforaprogramtomakeanobjectavailableforGarbageCollection.
D. Thefinalizemethodofanobjectisinvokedbeforegarbagecollectionisperformedon
theobject.
57. Ifabaseclasshasamethoddefinedas
voidmethod(){}
Whichofthefollowingarelegalprototypesinaderivedclassofthisclass.Selectthetwo
correctanswers.
A. voidmethod(){}
B. intmethod(){return0}
C. voidmethod(inti){}
D. privatevoidmethod(){}
58. Inwhichallcasesdoesanexceptiongetsgenerated.Selectthetwocorrectanswers.
inti=0,j=1

if((i==0)||(j/i==1))
if((i==0)|(j/i==1))
if((i!=0)&&(j/i==1))
if((i!=0)&(j/i==1))
59. Whichofthefollowingstatementsaretrue.Selectthetwocorrectanswers.
A. ThewaitmethoddefinedintheThreadclass,canbeusedtoconvertathreadfrom
RunningstatetoWaitingstate.
B. Thewait(),notify(),andnotifyAll()methodsmustbeexecutedinsynchronizedcode.
C. Thenotify()andnotifyAll()methodscanbeusedtosignalandmovewaitingthreadsto
readytorunstate.
D. TheThreadclassisanabstractclass.
60. Whichkeywordwhenappliedonamethodindicatesthatonlyonethreadshouldexecutethe
methodatatime.Selecttheonecorrectanswer.
A. transient
B. volatile
C. synchronized
D. native
A.
B.
C.
D.

E. static
F. final
61. WhatisthenameoftheCollectioninterfaceusedtorepresentelementsinasequence(ina

particularorder).Selecttheonecorrectanswer.
A. Collection
B. Set
C. List
D. Map
62. WhichoftheseclassesimplementtheCollectioninterfaceSortedMap.Selecttheonecorrect
answers.
A. HashMap
B. Hashtable
C. TreeMap
D. HashSet
E. TreeSet
F. Vector
63. Whichofthefollowingaretrueaboutinterfaces.Selectthetwocorrectanswers.
A. Methodsdeclaredininterfacesareimplicitlyprivate.
B. Variablesdeclaredininterfacesareimplicitlypublic,static,andfinal.
C. Aninterfacecanextendanynumberofinterfaces.
D. Thekeywordimplementsindicatethataninterfaceinheritsfromanother.
64. AssumethatclassAextendsclassB,whichextendsclassC.Alsoallthethreeclasses
implementthemethodtest().HowcanamethodinaclassAinvokethetest()methoddefinedin
classC(withoutcreatinganewinstanceofclassC).Selecttheonecorrectanswer.
A. test()
B. super.test()
C. super.super.test()
D. ::test()
E. C.test()
F. Itisnotpossibletoinvoketest()methoddefinedinCfromamethodinA.
65. Whatisthereturntypeofmethodround(doubled)definedinMathclass.
66. Whatgetswrittenonthescreenwhenthefollowingprogramiscompiledandrun.Selecttheone
rightanswer.
publicclasstest{
publicstaticvoidmain(Stringargs[]){
inti
floatf=2.3f
doubled=2.7
i=((int)Math.ceil(f))*((int)Math.round(d))
System.out.println(i)
}
}

A. 4

5
6
6.1
9
67. Isthefollowingstatementtrueorfalse.AsthetoStringmethodisdefinedintheObjectclass,
System.out.printlncanbeusedtoprintanyobject.
A. true
B. false
68. Whichoftheseclassesdefinedinjava.ioandusedforfilehandlingareabstract.Selectthetwo
correctanswers.
A. InputStream
B. PrintStream
C. Reader
D. FileInputStream
E. FileWriter
69. Namethecollectioninterfaceusedtorepresentcollectionsthatmaintainuniqueelements.
70. Whatistheresultofcompilingandrunningthefollowingprogram.
B.
C.
D.
E.

publicclasstest{
publicstaticvoidmain(Stringargs[]){
Stringstr1="abc"
Stringstr2="def"
Stringstr3=str1.concat(str2)
str1.concat(str2)
System.out.println(str1)
}
}

abc
def
abcabc
abcdef
defabc
abcdefdef
71. Selecttheonecorrectanswer.ThenumberofcharactersinanobjectofaclassStringisgiven
by
A. Themembervariablecalledsize
B. Themembervariablecalledlength
C. Themethodsize()returnsthenumberofcharacters.
D. Themethodlength()returnsthenumberofcharacters.
72. Selecttheonecorrectanswer.WhichmethoddefinedinIntegerclasscanbeusedtoconvertan
Integerobjecttoprimitiveinttype.
A. valueOf
B. intValue
C. getInt
A.
B.
C.
D.
E.
F.

D. getInteger
73. NamethereturntypeofmethodhashCode()definedinObjectclass,whichisusedtogetthe

uniquehashvalueofanObject.
74. Whichofthefollowingarecorrect.Selecttheonecorrectanswer.
A. Animportstatement,ifdefined,mustalwaysbethefirstnoncommentstatementofthe

file.
B. privatemembersareaccessibletoallclassesinthesamepackage.
C. Anabstractclasscanbedeclaredasfinal.
D. Localvariablescannotbedeclaredasstatic.
75. Namethekeywordthatmakesavariablebelongtoaclass,ratherthanbeingdefinedforeach
instanceoftheclass.Selecttheonecorrectanswer.
A. static
B. final
C. abstract
D. native
E. volatile
F. transient
76. Whichofthesearecoreinterfacesinthecollectionframework.Selecttheonecorrectanswer.
A. Tree
B. Stack
C. Queue
D. Array
E. LinkedList
F. Map
77. Whichofthesestatementsaretrue.Selectthetwocorrectanswers.
A. Foreachtryblocktheremustbeatleastonecatchblockdefined.
B. Atryblockmaybefollowedbyanynumberoffinallyblocks.
C. Atryblockmustbefollowedbyatleastonefinallyorcatchblock.
D. Ifbothcatchandfinallyblocksaredefined,catchblockmustprecedethefinallyblock.

AnswerstoSampleTest1

1. b
2. b,c,f
3. d.Notethattheprogramgetsonecommandlineargument2.args.lengthwillgetsetto1.So

theconditionif(args.length>1)willfail,andthesecondcheckif(args.length>0)willreturntrue.
4. arr.length
5. Anyoftheseiscorrect0x5,0x05,0X05,0X5
6. b,c,f,g
7. a
8. d
9. "am"
10. a,c.Pleasenotethatbisnotcorrect.Apackagestatementmayappearbeforeanimport

statement.Aclassconstructormaybedeclaredprivatealso.Hencedisincorrect.
11. a
12. a
13. protected
14. a,c
15. b,c
16. c
17. a,d,e
18. d,e
19. a,c
20. b,c
21. b,c,e
22. b
23. d
24. a
25. a
26. b,e.TheoptioncisincorrectbecauseaJavaidentifiernamecannotbeginwithadigit.
27. d
28. c
29. c,d
30. a,c
31. b,d
32. b,c
33. c
34. c
35. c
36. b,c
37. f
38. long
39. e
40. a
41. a,c
42. Set
43. a

44. d
45. b
46. int
47. d
48. a
49. f
50. c,d

Anda mungkin juga menyukai