Sunteți pe pagina 1din 14

25-06-13

javaprepare: Sample test 1 for SCJP 6

home|tutorial|questions|test1

FAQ JavaTutorial QuestionsbyTopic Mockexam1 Mockexam2 ThesampletestismodeledontheSunCertificationforJavaTM6Programmer OnlineJavaTraining exam.Thetesthas50questionsandneedstobeexecutedin2hours.Thereal OtherCertification exammaybealittletougherthanthis.Youneedtoscore35correctanswersout sites of60tocleartherealexamin180minutes.PleaseletusknowatngabraniAt CertificationTips ExamObjectives hotmaildotcomifyoufindanyissueswiththetest.Thesitealsooffersanother AboutJavaPrepare

Mockexam1forSCJP6

Books

mockexamandquestionsbytopic.

CertificationBooks SCEABooks OnlineBooks


TutorialTopics

Language Fundamentals Operatorand Assignments Declarationand AccessControl ClassesinJava Threads Files


Advertisements

1. Whichdeclarationofthemainmethodbelowwouldallowaclasstobe startedasastandaloneprogram.Selecttheonecorrectanswer. A. publicstaticintmain(charargs[]) B. publicstaticvoidmain(Stringargs[]) C. publicstaticvoidMAIN(Stringargs[]) D. publicstaticvoidmain(Stringargs) E. publicstaticvoidmain(charargs[]) 2. Whatallgetsprintedwhenthefollowingcodeiscompiledandrun? Selectthethreecorrectanswers.


p u b l i cc l a s sx y z{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ f o r ( i n ti=0 ;i<2 ;i + + ){ f o r ( i n tj=2 ;j > =0 ;j ){ i f ( i= =j )b r e a k ; S y s t e m . o u t . p r i n t l n ( " i = "+i+"j = " + j ) ; } } } }

A. i=0j=0 B. i=0j=1 C. i=0j=2 D. i=1j=0 E. i=1j=1 F. i=1j=2 G. i=2j=0 H. i=2j=1 I. i=2j=2 3. Whatgetsprintedwhenthefollowingcodeiscompiledandrunwiththe followingcommand

www.javaprepare.com/quests/test.html

1/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

javatest2 Selecttheonecorrectanswer.
p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ I n t e g e ri n t O b j = I n t e g e r . v a l u e O f ( a r g s [ a r g s . l e n g t h 1 ] ) ; i n ti=i n t O b j . i n t V a l u e ( ) ; i f ( a r g s . l e n g t h>1 ) S y s t e m . o u t . p r i n t l n ( i ) ; i f ( a r g s . l e n g t h>0 ) S y s t e m . o u t . p r i n t l n ( i-1 ) ; e l s e S y s t e m . o u t . p r i n t l n ( i-2 ) ;

4. 5. 6.

7.

8.

A. test B. test1 C. 0 D. 1 E. 2 InJavatechnologywhatexpressioncanbeusedtorepresentnumberof elementsinanarraynamedarr? Howwouldthenumber5berepresentedinhexusinguptofour characters. WhichofthefollowingisaJavakeyword.Selectthefourcorrect answers. A. extern B. synchronized C. volatile D. friend E. friendly F. transient G. this H. then Isthefollowingstatementtrueorfalse.Theconstructorofaclassmust nothaveareturntype. A. true B. false WhatisthenumberofbytesusedbyJavaprimitivelong.Selecttheone correctanswer. A. Thenumberofbytesiscompilerdependent. B. 2 C. 4

www.javaprepare.com/quests/test.html

2/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

9. 10.

11.

12.

13.

14.

15.

D. 8 E. 64 Whatisreturnedwhenthemethodsubstring(2,4)isinvokedonthestring "example"?IncludetheanswerinquotesastheresultisoftypeString. Whichofthefollowingiscorrect?Selectthetwocorrectanswers. A. Thenativekeywordindicatesthatthemethodisimplementedin anotherlanguagelikeC/C++. B. Theonlystatementsthatcanappearbeforeanimportstatementina Javafilearecomments. C. Themethoddefinitionsinsideinterfacesarepublicandabstract. Theycannotbeprivateorprotected. D. Aclassconstructormayhavepublicorprotectedkeywordbefore them,nothingelse. Whatistheresultofevaluatingtheexpression14^23.Selecttheone correctanswer. A. 25 B. 37 C. 6 D. 31 E. 17 F. 9 G. 24 Whichofthefollowingaretrue.Selecttheonecorrectanswers. A. &&operatorisusedforshortcircuitedlogicalAND. B. ~operatoristhebitwiseXORoperator. C. |operatorisusedtoperformbitwiseORandalsoshortcircuited logicalOR. D. TheunsignedrightshiftoperatorinJavais>>. Nametheaccessmodifierwhichwhenusedwithamethod,makesit availabletoalltheclassesinthesamepackageandtoallthesubclassesof theclass. Whichofthefollowingistrue.Selectthetwocorrectanswers. A. Aclassthatisabstractmaynotbeinstantiated. B. Thefinalkeywordindicatesthatthebodyofamethodistobe foundelsewhere.ThecodeiswritteninnonJavalanguage, typicallyinC/C++. C. Astaticvariableindicatesthereisonlyonecopyofthatvariable. D. Amethoddefinedasprivateindicatesthatitisaccessibletoall otherclassesinthesamepackage. Whatallgetsprintedwhenthefollowingprogramiscompiledandrun. Selectthetwocorrectanswers.

www.javaprepare.com/quests/test.html

3/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ i n ti ,j = 1 ; i=( j > 1 ) ? 2 : 1 ; s w i t c h ( i ){ c a s e0 :S y s t e m . o u t . p r i n t l n ( 0 ) ;b r e a k ; c a s e1 :S y s t e m . o u t . p r i n t l n ( 1 ) ; c a s e2 :S y s t e m . o u t . p r i n t l n ( 2 ) ;b r e a k ; c a s e3 :S y s t e m . o u t . p r i n t l n ( 3 ) ;b r e a k ; } } }

A. B. C. D.

0 1 2 3

16. Whatallgetsprintedwhenthefollowingprogramiscompiledandrun. Selecttheonecorrectanswer.

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ i n ti = 0 ,j = 2 ; d o{ i = + + i ; j ; }w h i l e ( j > 0 ) ; S y s t e m . o u t . p r i n t l n ( i ) ; } }

www.javaprepare.com/quests/test.html

4/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

A. 0 B. 1 C. 2 D. Theprogramdoesnotcompilebecauseofstatement"i=++i" 17. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Select thethreecorrectanswers.


p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ i n ti = 1 ,j = 1 ; t r y{ i + + ; j ; i f ( i / j>1 ) i + + ; } c a t c h ( A r i t h m e t i c E x c e p t i o ne ){ S y s t e m . o u t . p r i n t l n ( 0 ) ; } c a t c h ( A r r a y I n d e x O u t O f B o u n d s E x c e p t i o ne ){ S y s t e m . o u t . p r i n t l n ( 1 ) ; } c a t c h ( E x c e p t i o ne ){ S y s t e m . o u t . p r i n t l n ( 2 ) ; } f i n a l l y{ S y s t e m . o u t . p r i n t l n ( 3 ) ; } S y s t e m . o u t . p r i n t l n ( 4 ) ; } }

A. 0 B. 1 C. 2 D. 3 E. 4 18. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Select thetwocorrectanswers.

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ i n ti = 1 ,j = 1 ; t r y{ i + + ; j ; i f ( i= =j ) i + + ; }

www.javaprepare.com/quests/test.html

5/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

c a t c h ( A r i t h m e t i c E x c e p t i o ne ){ S y s t e m . o u t . p r i n t l n ( 0 ) ; } c a t c h ( A r r a y I n d e x O u t O f B o u n d s E x c e p t i o ne ){ S y s t e m . o u t . p r i n t l n ( 1 ) ; } c a t c h ( E x c e p t i o ne ){ S y s t e m . o u t . p r i n t l n ( 2 ) ; } f i n a l l y{ S y s t e m . o u t . p r i n t l n ( 3 ) ; } S y s t e m . o u t . p r i n t l n ( 4 ) ;

A. 0 B. 1 C. 2 D. 3 E. 4 19. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Select thetwocorrectanswers.

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ S t r i n gs 1=" a b c " ; S t r i n gs 2=" a b c " ; i f ( s 1= =s 2 ) S y s t e m . o u t . p r i n t l n ( 1 ) ; e l s e S y s t e m . o u t . p r i n t l n ( 2 ) ; i f ( s 1 . e q u a l s ( s 2 ) ) S y s t e m . o u t . p r i n t l n ( 3 ) ; e l s e S y s t e m . o u t . p r i n t l n ( 4 ) ; } }

A. 1 B. 2 C. 3 D. 4 20. Whatallgetsprintedwhenthefollowinggetscompiledandrun.Select thetwocorrectanswers.

www.javaprepare.com/quests/test.html

6/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ S t r i n gs 1=" a b c " ; S t r i n gs 2=n e wS t r i n g ( " a b c " ) ; i f ( s 1= =s 2 ) S y s t e m . o u t . p r i n t l n ( 1 ) ; e l s e S y s t e m . o u t . p r i n t l n ( 2 ) ; i f ( s 1 . e q u a l s ( s 2 ) ) S y s t e m . o u t . p r i n t l n ( 3 ) ; e l s e S y s t e m . o u t . p r i n t l n ( 4 ) ; }

21.

22.

23.

24.

A. 1 B. 2 C. 3 D. 4 Whichofthefollowingarelegalarraydeclarations.Selectthethree correctanswers. A. inti[5][] B. inti[][] C. int[]i[] D. inti[5][5] E. int[][]a Whatistherangeofvaluesthatcanbespecifiedforanint.Selecttheone correctanswer. A. Therangeofvaluesiscompilerdependent. B. 231to2311 C. 2311to231 D. 215to2151 E. 2151to215 Howcanyouensurethatthememoryallocatedbyanobjectisfreed. Selecttheonecorrectanswer. A. Byinvokingthefreemethodontheobject. B. Bycallingsystem.gc()method. C. Bysettingallreferencestotheobjecttonewvalues(saynull). D. Garbagecollectioncannotbeforced.Theprogrammercannotforce theJVMtofreethememoryusedbyanobject. Whatgetsprintedwhenthefollowingcodeiscompiledandrun.Select theonecorrectanswer.

www.javaprepare.com/quests/test.html

7/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ i n ti=1 ; d o{ i ; }w h i l e( i>2 ) ; S y s t e m . o u t . p r i n t l n ( i ) ; } }

A. 0 B. 1 C. 2 D. 1 25. Whichoftheseisalegaldefinitionofamethodnamedmassumingit throwsIOException,andreturnsvoid.Alsoassumethatthemethoddoes nottakeanyarguments.Selecttheonecorrectanswer. A. voidm()throwsIOException{} B. voidm()throwIOException{} C. voidm(void)throwsIOException{} D. m()throwsIOException{} E. voidm(){}throwsIOException 26. WhichofthefollowingarelegalidentifiernamesinJava.Selectthetwo correctanswers. A. %abcd B. $abcd C. 1abcd D. package E. _a_long_name 27. Atwhatstageinthefollowingmethoddoestheobjectinitiallyreferenced bysbecomesavailableforgarbagecollection.Selecttheonecorrect answer.

v o i dm e t h o dX ( ) { S t r i n gr=n e wS t r i n g ( " a b c " ) ; S t r i n gs=n e wS t r i n g ( " a b c " ) ; r=r + 1 ;/ / 1 r=n u l l ;/ / 2 s=s+r ;/ / 3 }/ / 4

A. Beforestatementlabeled1 B. Beforestatementlabeled2 C. Beforestatementlabeled3

www.javaprepare.com/quests/test.html

8/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

D. Beforestatementlabeled4 E. Never. 28. S t r i n gs=n e wS t r i n g ( " x y z " ) ; Assumingtheabovedeclaration,whichofthefollowingstatements wouldcompile.Selecttheonecorrectanswer. A. s=2*s B. inti=s[0] C. s=s+s D. s=s>>2 E. Noneoftheabove. 29. WhichofthefollowingstatementsrelatedtoGarbageCollectionare correct.Selectthetwocorrectanswers. A. Itispossibleforaprogramtofreememoryatagiventime. B. GarbageCollectionfeatureofJavaensuresthattheprogramnever runsoutofmemory. C. ItispossibleforaprogramtomakeanobjectavailableforGarbage Collection. D. Thefinalizemethodofanobjectisinvokedbeforegarbage collectionisperformedontheobject. 30. Ifabaseclasshasamethoddefinedas voidmethod(){} Whichofthefollowingarelegalprototypesinaderivedclassofthis class.Selectthetwocorrectanswers. A. voidmethod(){} B. intmethod(){return0} C. voidmethod(inti){} D. privatevoidmethod(){} 31. Inwhichallcasesdoesanexceptiongetsgenerated.Selectthetwo correctanswers.
i n ti=0 ,j=1 ;

A. if((i==0)||(j/i==1)) B. if((i==0)|(j/i==1)) C. if((i!=0)&&(j/i==1)) D. if((i!=0)&(j/i==1)) 32. Whichofthefollowingstatementsaretrue.Selectthetwocorrect answers. A. ThewaitmethoddefinedintheThreadclass,canbeusedto convertathreadfromRunningstatetoWaitingstate. B. Thewait(),notify(),andnotifyAll()methodsmustbeexecutedin synchronizedcode. C. Thenotify()andnotifyAll()methodscanbeusedtosignaland movewaitingthreadstoreadytorunstate. D. TheThreadclassisanabstractclass.

www.javaprepare.com/quests/test.html

9/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

33. Whichkeywordwhenappliedonamethodindicatesthatonlyonethread shouldexecutethemethodatatime.Selecttheonecorrectanswer. A. transient B. volatile C. synchronized D. native E. static F. final 34. WhatisthenameoftheCollectioninterfaceusedtorepresentelementsin asequence(inaparticularorder).Selecttheonecorrectanswer. A. Collection B. Set C. List D. Map 35. WhichoftheseclassesimplementtheCollectioninterfaceSortedMap. Selecttheonecorrectanswers. A. HashMap B. Hashtable C. TreeMap D. HashSet E. TreeSet F. Vector 36. Whichofthefollowingaretrueaboutinterfaces.Selectthetwocorrect answers. A. Methodsdeclaredininterfacesareimplicitlyprivate. B. Variablesdeclaredininterfacesareimplicitlypublic,static,and final. C. Aninterfacecanextendanynumberofinterfaces. D. Thekeywordimplementsindicatethataninterfaceinheritsfrom another. 37. AssumethatclassAextendsclassB,whichextendsclassC.Alsoallthe threeclassesimplementthemethodtest().HowcanamethodinaclassA invokethetest()methoddefinedinclassC(withoutcreatinganew instanceofclassC).Selecttheonecorrectanswer. A. test() B. super.test() C. super.super.test() D. ::test() E. C.test() F. Itisnotpossibletoinvoketest()methoddefinedinCfroma methodinA. 38. Whatisthereturntypeofmethodround(doubled)definedinMathclass. 39. Whatgetswrittenonthescreenwhenthefollowingprogramiscompiled andrun.Selecttheonerightanswer.
www.javaprepare.com/quests/test.html 10/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ i n ti ; f l o a t f=2 . 3 f ; d o u b l ed=2 . 7 ; i=( ( i n t ) M a t h . c e i l ( f ) )*( ( i n t ) M a t h . r o u n d ( d ) ) ; S y s t e m . o u t . p r i n t l n ( i ) ; }

40.

41.

42. 43.

A. 4 B. 5 C. 6 D. 6.1 E. 9 Isthefollowingstatementtrueorfalse.AsthetoStringmethodisdefined intheObjectclass,System.out.printlncanbeusedtoprintanyobject. A. true B. false Whichoftheseclassesdefinedinjava.ioandusedforfilehandlingare abstract.Selectthetwocorrectanswers. A. InputStream B. PrintStream C. Reader D. FileInputStream E. FileWriter Namethecollectioninterfaceusedtorepresentcollectionsthatmaintain uniqueelements. Whatistheresultofcompilingandrunningthefollowingprogram.
p u b l i cc l a s st e s t{ p u b l i cs t a t i cv o i dm a i n ( S t r i n ga r g s [ ] ){ S t r i n gs t r 1 = " a b c " ; S t r i n gs t r 2 = " d e f " ; S t r i n gs t r 3 = s t r 1 . c o n c a t ( s t r 2 ) ; s t r 1 . c o n c a t ( s t r 2 ) ; S y s t e m . o u t . p r i n t l n ( s t r 1 ) ;

A. B. C. D. E.

abc def abcabc abcdef defabc

www.javaprepare.com/quests/test.html

11/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

F. abcdefdef 44. Selecttheonecorrectanswer.Thenumberofcharactersinanobjectofa classStringisgivenby A. Themembervariablecalledsize B. Themembervariablecalledlength C. Themethodsize()returnsthenumberofcharacters. D. Themethodlength()returnsthenumberofcharacters. 45. Selecttheonecorrectanswer.WhichmethoddefinedinIntegerclasscan beusedtoconvertanIntegerobjecttoprimitiveinttype. A. valueOf B. intValue C. getInt D. getInteger 46. NamethereturntypeofmethodhashCode()definedinObjectclass, whichisusedtogettheuniquehashvalueofanObject.

47. Whichofthefollowingarecorrect.Selecttheonecorrectanswer. A. Animportstatement,ifdefined,mustalwaysbethefirstnon commentstatementofthefile. B. privatemembersareaccessibletoallclassesinthesamepackage. C. Anabstractclasscanbedeclaredasfinal. D. Localvariablescannotbedeclaredasstatic. 48. Namethekeywordthatmakesavariablebelongtoaclass,ratherthan beingdefinedforeachinstanceoftheclass.Selecttheonecorrect answer. A. static B. final C. abstract D. native E. volatile F. transient
www.javaprepare.com/quests/test.html 12/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

49. Whichofthesearecoreinterfacesinthecollectionframework.Selectthe onecorrectanswer. A. Tree B. Stack C. Queue D. Array E. LinkedList F. Map 50. Whichofthesestatementsaretrue.Selectthetwocorrectanswers. A. Foreachtryblocktheremustbeatleastonecatchblockdefined. B. Atryblockmaybefollowedbyanynumberoffinallyblocks. C. Atryblockmustbefollowedbyatleastonefinallyorcatchblock. D. Ifbothcatchandfinallyblocksaredefined,catchblockmust precedethefinallyblock. AnswerstoSampleTest1 1. b 2. b,c,f 3. d.Notethattheprogramgetsonecommandlineargument2.args.length willgetsetto1.Sotheconditionif(args.length>1)willfail,andthe secondcheckif(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.Apackagestatementmayappear beforeanimportstatement.Aclassconstructormaybedeclaredprivate also.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

www.javaprepare.com/quests/test.html

13/14

25-06-13

javaprepare: Sample test 1 for SCJP 6

23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50.

d a a b,e.TheoptioncisincorrectbecauseaJavaidentifiernamecannot beginwithadigit. d c c,d a,c b,d b,c c c c b,c f long e a a,c Set a d b int d a f c,d

home|tutorial|questions|test1|test2

www.javaprepare.com/quests/test.html

14/14

S-ar putea să vă placă și