欢迎来到天天文库
浏览记录
ID:42604978
大小:19.19 KB
页数:9页
时间:2019-09-18
《Java基础测试(二)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Java测试QUESTIONNO:1Given:1.publicclassTest{2.publicstaticvoidmain(Stringargs[]){3.classFoo{4.publicinti=3;5.}6.Objecto=(Object)newFoo();7.Foofoo=(Foo)o;8.System.out.println("i="+foo.i);9.}10.}结果是(不)A.i=3B.程序编译错误.C.第6行代码有问题.D.第7行代码有问题.QUESTIONNO:2Given:下面代码有编译错误是(A)A.float[]=newfloat(3);B.floatf
2、2[]=newfloat[];C.float[]f1=newfloat[3];D.floatf3[]=newfloat[3];E.floatf5[]={1.0f,2.0f,2.0f};F.floatf4[]=newfloat[]{1.0f,2.0f,3.0f};QUESTIONNO:3Given:1.inti=1,j=10;2.do{3.if(i++>--j){4.continue;5.}6.}while(i<5);7.System.out.println("i="+i+"andj="+j);结果是(D)A.i=6andj=5B.i=5andj=5C.i=6andj=5D.i=5a
3、ndj=6E.i=6andj=6QUESTIONNO:4Given:1.interfaceAnimal{2.voidsoundOff();3.}4.5.classElephantimplementsAnimal{6.publicvoidsoundOff(){7.System.out.println("Trumpet");8.}9.}10.11.classLionimplementsAnimal{12.publicvoidsoundOff(){13.System.out.println("Roar");14.}15.}16.17.classAlpha1{18.staticAnimal
4、get(Stringchoice){19.if(choice.equalsIgnoreCase("meateater")){20.returnnewLion();21.}else{22.returnnewElephant();23.}24.}25.}下面选项中代码哪个可以编译通过(A)A.newAnimal().soundOff();B.Elephante=newAlpha1();C.Lion1=Alpha.get("meateater");D.newAlpha1().get("veggie").soundOff();QUESTIONNO:5Given:1.inti=1,j=10;
5、2.do{3.if(i>j){4.break;5.}6.j--;7.}while(++i<5);8.System.out.println("i="+i+"andj="+j);程序结果是(D)A.i=6andj=5B.i=5andj=5C.i=6andj=4D.i=5andj=6E.i=6andj=6QUESTIONNO:6Given:你要想一个类能够访问同一个包下其他类的属性,请问选择下面哪个选项(C)A.publicB.privateC.protectedD.transientE.defaultaccessQUESTIONNO:7Given:1.intx=3;2.inty=1;3
6、.if(x=y){4.System.out.println("x="+x);5.}代码结果是(C)A.x=1B.x=3C.程序编译错误.D.代码运行结束后没有输出结果.E.代码运行时候会有错误.QUESTIONNO:8Given:1.publicinterfaceFoo{2.intk=4;3.}下面哪些选项能够放到程序的第2行位置(A,B,C)A.finalintk=4;B.publicintk=4;C.staticintk=4;D.abstractintk=4;E.volatileintk=4;F.protectedintk=4;QUESTIONNO:9Given:1.packa
7、getest1;2.publicclassTest1{3.staticintx=42;4.}1.packagetest2;2.publicclassTest2extendstest1.Test1{3.publicstaticvoidmain(String[]args){4.System.out.println("x="+x);5.}6.}程序代码结果是(B)A.x=0B.x=42C.Test2类中第2行代码有错误.D.Test1类中第3行代码有错误.E.Test2类中
此文档下载收益归作者所有