SCJP Mock Exam 1.docx
- 文档编号:26698452
- 上传时间:2023-06-21
- 格式:DOCX
- 页数:40
- 大小:24.56KB
SCJP Mock Exam 1.docx
《SCJP Mock Exam 1.docx》由会员分享,可在线阅读,更多相关《SCJP Mock Exam 1.docx(40页珍藏版)》请在冰豆网上搜索。
SCJPMockExam1
Q1
Amethodis...
1)animplementationofanabstraction.
2)anattributedefiningthepropertyofaparticularabstraction.
3)acategoryofobjects.
4)anoperationdefiningthebehaviorforaparticularabstraction.
5)ablueprintformakingoperations.
Q2
Anobjectis...
1)whatclassesareinstantiatedfrom.
2)aninstanceofaclass.
3)ablueprintforcreatingconcreterealizationofabstractions.
4)areferencetoanattribute.
5)avariable.
Q3
Whichlinecontainsaconstructorinthisclassdefinition?
publicclassCounter{//
(1)
intcurrent,step;
publicCounter(intstartValue,intstepValue){//
(2)
set(startValue);
setStepValue(stepValue);
}
publicintget(){returncurrent;}//(3)
publicvoidset(intvalue){current=value;}//(4)
publicvoidsetStepValue(intstepValue){step=stepValue;}//(5)
}
1)Codemarkedwith
(1)isaconstructor
2)Codemarkedwith
(2)isaconstructor
3)Codemarkedwith(3)isaconstructor
4)Codemarkedwith(4)isaconstructor
5)Codemarkedwith(5)isaConstructor
Q4
GiventhatThingisaclass,howmanyobjectsandreferencevariablesarecreatedbythefollowingcode?
Thingitem,stuff;
item=newThing();
Thingentity=newThing();
1)Oneobjectiscreated
2)Twoobjectsarecreated
3)Threeobjectsarecreated
4)Onereferencevariableiscreated
5)Tworeferencevariablesarecreated
6)Threereferencevariablesarecreated.
Q5
Aninstancemember…
1)isalsocalledastaticmember
2)isalwaysavariable
3)isneveramethod
4)belongstoasingleinstance,nottotheclassasawhole
5)alwaysrepresentsanoperation
Q6
HowdoobjectspassmessagesinJava?
1)Theypassmessagesbymodifyingeachother'smembervariables
2)Theypassmessagesbymodifyingthestaticmembervariablesofeachother'sclasses
3)Theypassmessagesbycallingeachother'sinstancemembermethods
4)Theypassmessagesbycallingstaticmembermethodsofeachother'sclasses.
Q7
Giventhefollowingcode,whichstatementsaretrue?
classA{
intvalue1;
}
classBextendsA{
intvalue2;
}
1)ClassAextendsclassB.
2)ClassBisthesuperclassofclassA.
3)ClassAinheritsfromclassB.
4)ClassBisasubclassofclassA.
5)ObjectsofclassAhaveamembervariablenamedvalue2.
Q8
IfthissourcecodeiscontainedinafilecalledSmallProg.java,whatcommandshouldbeusedtocompileitusingtheJDK?
publicclassSmallProg{
publicstaticvoidmain(Stringargs[]){System.out.println("Goodluck!
");}
}
1)javaSmallProg
2)avacSmallProg
3)javaSmallProg.java
4)javacSmallProg.java
5)javaSmallProgmain
Q9
Giventhefollowingclass,whichstatementscanbeinsertedatposition1withoutcausingthecodetofailcompilation?
publicclassQ6db8{
inta;
intb=0;
staticintc;
publicvoidm(){
intd;
inte=0;
//Position1
}
}
1)a++;
2)b++;
3)c++;
4)d++;
5)e++;
Q10
Whichstatementsaretrueconcerningtheeffectofthe>>and>>>operators?
1)Fornon-negativevaluesoftheleftoperand,the>>and>>>operatorswillhavethesameeffect.
2)Theresultof(-1>>1)is0.
3)Theresultof(-1>>>1)is-1.
4)Thevaluereturnedby>>>willneverbenegativeaslongasthevalueoftherightoperandisequaltoorgreaterthan1.
5)Whenusingthe>>operator,theleftmostbitofthebitrepresentationoftheresultingvaluewillalwaysbethesamebitvalueastheleftmostbitofthebitrepresentationoftheleftoperand.
Q11
Whatiswrongwiththefollowingcode?
classMyExceptionextendsException{}
publicclassQb4ab{
publicvoidfoo(){
try{
bar();
}finally{
baz();
}catch(MyExceptione){}
}
publicvoidbar()throwsMyException{
thrownewMyException();
}
publicvoidbaz()throwsRuntimeException{
thrownewRuntimeException();
}
}
1)Sincethemethodfoo()doesnotcatchtheexceptiongeneratedbythemethodbaz(),itmustdeclaretheRuntimeExceptioninitsthrowsclause.
2)Atryblockcannotbefollowedbybothacatchandafinallyblock.
3)Anemptycatchblockisnotallowed.
4)Acatchblockcannotfollowafinallyblock.
5)Afinallyblockmustalwaysfollowoneormorecatchblocks.
Q12
Whatwillbewrittentothestandardoutputwhenthefollowingprogramisrun?
publicclassQd803{
publicstaticvoidmain(Stringargs[]){
Stringword="restructure";
System.out.println(word.substring(2,3));
}
}
1)est
2)es
3)str
4)st
5)s
Q13
GiventhatastaticmethoddoIt()inaclassWorkrepresentsworktobedone,whatblockofcodewillsucceedinstartinganewthreadthatwilldothework?
CODEBLOCKA:
Runnabler=newRunnable(){
publicvoidrun(){
Work.doIt();
}
};
Threadt=newThread(r);
t.start();
CODEBLOCKB:
Threadt=newThread(){
publicvoidstart(){
Work.doIt();
}
};
t.start();
CODEBLOCKC:
Runnabler=newRunnable(){
publicvoidrun(){
Work.doIt();
}
};
r.start();
CODEBLOCKD:
Threadt=newThread(newWork());
t.start();
CODEBLOCKE:
Runnablet=newRunnable(){
publicvoidrun(){
Work.doIt();
}
};
t.run();
1)CodeblockA.
2)CodeblockB.
3)CodeblockC.
4)CodeblockD.
5)CodeblockE.
Q14
WritealineofcodethatdeclaresavariablenamedlayoutoftypeLayoutManagerandinitializesitwithanewobject,whichwhenusedwithacontainercanlayoutcomponentsinarectangulargridofequal-sizedrectangles,3componentswideand2componentshigh.
Q15
publicclassQ275d{
staticinta;
intb;
publicQ275d(){
intc;
c=a;
a++;
b+=c;
}
publicstaticvoidmain(Stringargs[]){
newQ275d();
}
}
1)Thecodewillfailtocompile,sincetheconstructoristryingtoaccessstaticmembers.
2)Thecodewillfailtocompile,sincetheconstructoristryingtousestaticmembervariableabeforeithasbeeninitialized.
3)Thecodewillfailtocompile,sincetheconstructoristryingtousemembervariablebbeforeithasbeeninitialized.
4)Thecodewillfailtocompile,sincetheconstructoristryingtouselocalvariablecbeforeithasbeeninitialized.
5)Thecodewillcompileandrunwithoutanyproblems.
Q16
Whatwillbewrittentothestandardoutputwhenthefollowingprogramisrun?
publicclassQ63e3{
publicstaticvoidmain(Stringargs[]){
System.out.println(9^2);
}
}
1)81
2)7
3)11
4)0
5)false
Q17
Whichstatementsaretrueconcerningthedefaultlayoutmanagerforcontainersinthejava.awtpackage?
1)ObjectsinstantiatedfromPaneldonothaveadefaultlayoutmanager.
2)ObjectsinstantiatedfromPanelhaveFlowLayoutasdefaultlayoutmanager.
3)ObjectsinstantiatedfromApplethaveBorderLayoutasdefaultlayoutmanager.
4)ObjectsinstantiatedfromDialoghaveBorderLayoutasdefaultlayoutmanager.
5)ObjectsinstantiatedfromWindowhavethesamedefaultlayoutmanagerasinstancesofApplet.
Q18
Whichdeclarationswillallowaclasstobestartedasastandaloneprogram?
1)publicvoidmain(Stringargs[])
2)publicvoidstaticmain(Stringargs[])
3)publicstaticmain(String[]argv)
4)finalpublicstaticvoidmain(String[]array)
5)publicstaticvoidmain(Stringargs[])
Q19
Underwhichcircumstanceswillathreadstop?
1)ThemethodwaitforId()inclassMediaTrackeriscalled.
2)Therun()methodthatthethreadisexecutingends.
3)Thecalltothestart()methodoftheThreadobjectreturns.
4)Thesuspend()methodiscalledontheThreadobject.
5)Thewait()methodiscalledontheThreadobject.
Q20
Whencreatingaclassthatassociatesasetofkeyswithasetofvalues,whichoftheseinterfacesismostapplicable?
1)Collection
2)Set
3)SortedSet
4)Map
Q21
WhatdoesthevaluereturnedbythemethodgetID()foundinclassjava.awt.AWTEventuniquelyidentify?
1)Theparticulareventinstance.
2)Thesourceoftheevent.
3)Thesetofeventsthatweretriggeredbythesameaction.
4)Thetypeofevent.
5)Thetypeofcomponentfromwhichtheeventoriginated.
Q22
Whatwillbewrittentothestandardoutputwhenthefollowingprogramisrun?
classBase{
inti;
Base(){
add
(1);
}
voidadd(intv){
i+=v;
}
voidprint(){
System.out.println(i);
}
}
classExtensionextendsBase{
Extension(){
add
(2);
}
voidadd(intv){
i+=v*2;
}
}
publicclassQd073{
publicstaticvoidmain(Stringargs[]){
bogo(newExtension());
}
staticvoidbogo(Baseb){
b.add(8);
b.print();
}
}
1)9
2)18
3)20
4)21
5)22
Q23
Whichlinesofcodearevaliddeclarationsofanativemethodwhenoccurringwithinthedeclarationofthefollowingclass?
publicclassQf575{
//insertdeclarationofanativemethodhere
}
1)nativepublicvoidsetTemperature(intkelvin);
2)privatenativevoidsetTemperature(intkelvin);
3)protectedintnativegetTemperature();
4)publicabstractnativevoidsetTemperature(intkelvin);
5)nativeintsetTemperature(intkelvin){}
Q24
HowdoestheweightypropertyoftheGridBagConstraintsobjectsusedingridbaglayoutaffectthelayoutofthecomponents?
1)Itaffectswhichgridcellthecomponentsendupin.
2)Itaffectshowtheextraverticalspaceisdistributed.
3)Itaffectsthealignmentofeachcomponent.
4)Itaffectswhetherthecomponentscompletelyfilltheirallotteddisplayareavertically.
Q25
Whichstatementscanbeinsertedattheindicatedpositioninthefollowingcodetomaketheprogramwrite1onthestandardoutputwhenrun?
publicclassQ4a39{
inta=1;
intb=1;
intc=1;
classInner{
inta=2;
intget(){
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SCJP Mock Exam