System.out.println(ar[i]);
}
}
a)5个0的序列会被输出
b)Error:
ar在使用前要初始化
c)ErrorMine必须被声明为abstract
d)Error数组越界
12)试图编译运行下面的代码会输出什么样的结果(c)
inti=1;
switch(i){
case0:
System.out.println("zero");
break;
case1:
System.out.println("one");
case2:
System.out.println("two");
default:
System.out.println("default");
}
a)one
b)one,default
c)one,two,default
d)default
13)试图编译运行下面的代码会输出什么样的结果(b)
inti=9;
switch(i){
default:
System.out.println("default");
case0:
System.out.println("zero");
break;
case1:
System.out.println("one");
case2:
System.out.println("two");
}
a)default
b)default,zero
c)errordefault没有定义
d)无输出
14)下面的哪些组代码没有编译错误(多选)(b,C)
a)
inti=0;
if(i){
System.out.println("Hello");
}
b)
booleanb=true;
booleanb2=true;
if(b==b2){
System.out.println("Sotrue");
}
c)
inti=1;
intj=2;
if(i==1||j==2)
System.out.println("OK");
d)
inti=1;
intj=2;
if(i==1&|j==2)
System.out.println("OK");
15如果在当前目录下不存在Hello.txt文件,试图编译和运行下面代码会输出什么(c)
importjava.io.*;
publicclassMine{
publicstaticvoidmain(Stringargv[]){
Minem=newMine();
System.out.println(m.amethod());
}
publicintamethod(){
try{
FileInputStreamdis=newFileInputStream("Hello.txt");
}catch(FileNotFoundExceptionfne){
System.out.println("Nosuchfilefound");
return-1;
}catch(IOExceptionioe){
}finally{
System.out.println("Doingfinally");
}
return0;
}
}
a)Nosuchfilefound
b)Nosuchfilefound,-1
c)Nosuchfilefound,Doingfinally,-1//finally语句回执行在return之前:
d)0
16)在下面的注释处插入哪些部分代码是合法的(多选)
classBase{
publicvoidamethod(inti){}
}
publicclassScopeextendsBase{
publicstaticvoidmain(Stringargv[]){
}
//在这里定义一个方法
}
a)voidamethod(inti)throwsException{}
b)voidamethod(longi)throwsException{}
c)voidamethod(longi){}
d)publicvoidamethod(inti)throwsException{}
17)下面哪行代码输出-4.0(C)
a)System.out.println(Math.floor(-4.7));//返回<=参数的最大整数
b)System.out.println(Math.round(-4.7));//返回最接近参数的long型值
c)System.out.println(Math.ceil(-4.7));//返回>=参数的最小整数
d)System.out.println(Math.min(-4.7));//返回参数中的最小值
18)如果运行下面的代码会输出什么内容
(2)
Strings=newString("Bicycle");
intiBegin=1;
chariEnd=3;
System.out.println(s.substring(iBegin,iEnd));//subString()是String的方法,在这里的用法是输出1~~~3位的字符
1)Bic
2)ic
3)icy
4)error:
没有匹配的方法substring(int,char)
19)给出下面的代码在注释部分放置什么样的代码会输出“Equal”(c)
publicclassEqTest{
publicstaticvoidmain(Stringargv[]){
EqTeste=newEqTest();
}
EqTest(){
Strings="Java";
Strings2="java";
//placetesthere{
System.out.println("Equal");
}else
{
System.out.println("Notequal");
}
}
}
a)if(s==s2)
b)if(s.equals(s2)
c)if(s.equalsIgnoreCase(s2))
d)if(s.noCaseMatch(s2))
20)给出下面的代码,怎样调用Base的构造方法会输出"baseconstructor"(c)
classBase{
Base(inti){
System.out.println("baseconstructor");
}
Base(){
}
}
publicclassSupextendsBase{
publicstaticvoidmain(Stringargv[]){
Sups=newSup();
//One
}
Sup()
{
//Two
}
publicvoidderived()
{
//Three
}
}
a)//One后放置Base(10);
b)//One后放置super(10);
c)//Two后放置super(10);
d)//Three后放置super(10);
参考答案:
1-5eaaad
6-10bbcdedcc
11-15ccbbcc
16-20bccbcd