欢迎来到天天文库
浏览记录
ID:6380225
大小:156.50 KB
页数:35页
时间:2018-01-12
《java阶段考试 考题及答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Given:1.publicclassBarn{2.publicstaticvoidmain(String[]args){3.newBarn.go("hi",1);4.newBarn.go("hi","world",2);5.}6.publicvoidgo(String...y,intx){7.System.out.print(y[y.length-1]+"");8.}9.}Whatistheresult?A.hihiB.hiworldC.worldworldD.Compilationfails.答案:DGiven:11.classMud{12.//insert
2、codehere13.System.out.println("hi");14.}15.}Andthefollowingfivefragments:publicstaticvoidmain(String...a){publicstaticvoidmain(String.*a){publicstaticvoidmain(String...a){publicstaticvoidmain(String[]...a){publicstaticvoidmain(String...[]a){Howmanyofthecodefragments,insertedindepende
3、ntlyatline12,compile?A.0B.1C.2D.3答案:DGiven:WhichManclassproperlyrepresentstherelationship"ManhasabestfriendwhoisaDog"?A.classManextendsDog{}B.classManimplementsDog{}C.classMan{privateBestFrienddog;}D.classMan{privateDogbestFriend;}答案:DGiven:1.classPass{2.publicstaticvoidmain(String[]
4、args){3.intx=5;4.Passp=newPass();5.p.doStuff(x);6.System.out.print("mainx="+x);7.}8.voiddoStuff(intx){9.System.out.println("doStuffx="+x++);10.}11.}Whatistheresult?A.Compilationfails.B.Anexceptionisthrownatruntime.C.doStuffx=6mainx=6D.doStuffx=5mainx=5答案:DGiven:1.classClassA{2.public
5、intnumberOfInstances;3.protectedClassA(intnumberOfInstances){4.this.numberOfInstances=numberOfInstances;5.}6.}7.classExtendedAextendsClassA{8.privateExtendedA(intnumberOfInstances){9.super(numberOfInstances);10.}11.publicstaticvoidmain(String[]args){12.ExtendedAext=newExtendedA(420);
6、13.System.out.print(ext.numberOfInstances);Whatistheresult?A.420istheoutputB.Anexceptionisthrownatruntime.C.Allconstructorsmustbedeclaredpublic.D.ConstructorsCANNOTusetheprivatemodifier.答案:AGiven:1.publicclassA{2.publicvoiddoit(){3.}4.publicStringdoit(){5.return"a";6.}7.publicdoubled
7、oit(intx){8.return1.0;9.}10.}Whatistheresult?A.Anexceptionisthrownatruntime.B.Compilationfailsbecauseofanerrorinline7.C.Compilationfailsbecauseofanerrorinline4.D.CompilationsucceedsandnoruntimeerrorswithclassAoccur.答案:CGiven:10.publicclassHello{11.Stringtitle;12.intvalue;13.publicHel
8、lo(){14.titl
此文档下载收益归作者所有