6.
7.System.out.println(i[a]);
8.}
9.}
10.}"
答案:
C
A.i[1]=((int)Math.min(x[a]));
B.i[1]=((int)Math.max(x[a]));
C.i[1]=((int)Math.ceil(x[a]));
D.i[1]=((int)Math.floor(x[a]));
8.下列哪些项是泛型的优点?
答案:
A
A.不用向下强制类型转换
B.代码容易编写
C.类型安全
D.运行速度快
9.以下哪些是Collection接口的子接口?
答案:
BD
A.Dictionary
B.List
C.Map
D.Set
10.以下哪些集合接口支持重复元素存在?
答案:
B
A.Collection
B.List
C.Map
D.Set
11.以下说法正确的是()
答案:
A.RandomAccessFile类是File类的子类
B.FileWriter类提供有操作基本数据类型的方法
C.RandomAccessFile类提供有删除磁盘文件的方法
D.File类提供有删除磁盘文件的方法
12.List接口的特点是哪项?
答案:
C
A.不允许重复元素,元素有顺序
B.允许重复元素,元素无顺序
C.允许重复元素,元素有顺序
D.不允许重复元素,元素无顺序
13."以下代码的输出结果是什么?
选择所有的正确答案。
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
for(inti=0;i<10;i++){
try{
try{
if(i%3==0)
thrownewException(""E0"");
System.out.println(i);break;
}catch(Exceptioninner){
i*=2;
if(i%3==0)
thrownewException(""E1"");
}finally{
++i;
}
}catch(Exceptionouter){
i+=3;
}finally{
--i;
}
}
}
}"
答案:
A.4
B.5
C.6
D.7
14."下列代码执行后的输出是哪项?
publicclassExample{
publicstaticvoidmain(String[]args){
Listal=newArrayList();
al.add(""1"");
al.add(""2"");
al.add(""2"");
al.add(""3"");
System.out.println(al);
}
}"
答案:
A.[1,2,3]
B.[1,2,3,3]
C.[1,2,2,3]
D.[2,1,3,2]
15."现有:
list是一个合法的集合引用
getCollection()返回一个合法集合的引用,以下语句哪些是合法的?
"
答案:
C
A.for(Objecto:
list)
B.for(Objecto:
getCollection())
C.for(Objecto:
list.iterator())
D.for(IteratorI;list.iterator();i.hasNext())
16."以下代码的执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
TreeSett=newTreeSet();
if(t.add(""one""))
if(t.add(""two""))
if(t.add(""three""))
t.add(""four"");
for(Strings:
t){
System.out.print(s);
}
}
}"
答案:
D
A.one
B.onethreetwo
C.onetwothreefour
D.fouronethreetwo
17."现有:
publicclassExample{
publicstaticvoidmain(String[]args){
TreeSets=newTreeSet();
s.add(""one"");
s.add(""two"");
//插入代码处
for(Strings2:
sorted){
System.out.print(s2+"""");
}
}
}
和四个代码片段:
s1:
SortedSetsorted=s.tailSet(s.first());
s2:
SortedSetsorted=s.tailSet(s.first());
s3:
SortedSetsorted=(SortedSet)s.tailSet(s.first());
s4:
SortedSetsorted=(SortSet)s.tailSet(s.first());
分别插入到插入代码处,哪项可以编译?
"
答案:
A.S2
B.S2和S3
C.S2和S4
D.S2、S3和S4
18."以下代码执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
TreeMapmap=newTreeMap();
map.put(""one"",""1"");
map.put(""two"",""2"");
map.put(""three"",""3"");
displayMap(map);
}
staticvoiddisplayMap(TreeMapmap){
Collectionc=map.entrySet();
Iteratori=c.iterator();
while(i.hasNext()){
Objecto=i.next();
System.out.print(o.toString());
}
}
}"
答案:
A.onetwothree
B.123
C.one=1three=3two=2
D.onethreetwo
19."现有如下类型:
a-java.util.Hashtable
b-java.util.List
c-java.util.ArrayList
d-java.util.SortedSet
和定义:
1-使用本接口,允许用户控制集合中每个元素的插入位置
2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合
3-本具体类型允许空元素及基于索引的访问
4-本集合是同步的
哪一组匹配是对的?
"
答案:
A.2描述d,3描述b
B.1描述b,3描述c
C.3描述a,4描述b
D.4描述a,2描述c
20."现有:
publicclassExample{
publicstaticvoidmain(String[]args){
//插入代码处
c.put(""X"",123);
}
}
下列哪些插入到插入代码处能够正常编译?
"
答案:
A.Mapc=newSortedMap();
B.HashMapc=newHashMap();
C.SortedMapc=newTreeMap();
D.Mapc=newLinkedHashMap();
21.以下哪些类提供了创建一个目录的方法?
答案:
A
A.File
B.DataOutput
C.Directory
D.FileDescriptor
22."现有以下代码:
interfaceW{
}
classZimplementsW{
}
classXextendsZ{
}
classYextendsZ{
}
下列哪些代码段是正确的?
"
答案:
A."Xx=newX();
Yy=newY();
Zz=newZ();
y=(Y)x;"
B."Xx=newX();
Yy=newY();
Zz=newZ();
x=(X)y;"
C."Xx=newX();
Yy=newY();
Zz=newZ();
Z=(Z)x;"
D."Xx=newX();
Yy=newY();
Zz=newZ();
Ww=(W)x;"
23.表示键值对概念的接口是哪项?
答案:
D
A.Set
B.List
C.Collection
D.Map
24.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?
答案:
C
A.raiseServiceException
B.thrownewServiceException()
C.throwServiceException
D.throwsServiceException
25.以下哪些方法在Class类中定义?
答案:
A.getConstructors()
B.getPrivateMethods()
C.getDeclaredFields()
D.getImports()
26."现有代码:
publicclassExample{
publicstaticvoidmain(String[]args){
try{
System.out.print(Integer.parseInt(""forty""));
}catch(RuntimeExceptione){
System.out.println(""Runtime"");
}catch(NumberFormatExceptione){
System.out.println(""Number"");
}
}
}
执行结果是什么?
"
答案:
C
A.输出Number
B.输出Runtime
C.输出40
D.编译失败
27."现有如下代码:
publicclassExampleextendsUtils{
publicstaticvoidmain(String[]args){
try{
System.out.println(newExample().getInt(""42""));
}catch(NumberFormatExceptione){
System.out.println(""NFExc"");
}
}
intgetInt(Stringarg)throwsNumberFormatException{
returnInteger.parseInt(arg);
}
}
classUtils{
intgetInt(Stringarg){
return42;
}
}
该代码执行的结果是?
"
答案:
B
A.NFExc
B.42
C.42NFExc
D.编译失败
28.关于异常处理,说法错误的是?
答案:
C
A.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一
B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面
C.一个方法可以抛出多个异常,方法的返回值也能够是异常
D.Throwable是所有异常的超类
29."关于以下代码,说法正确的是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
System.out.println(""BeforeTry"");
try{
}catch(Throwablee){
System.out.println(""InsideCatch"");
}
System.out.println(""AttheEnd"");
}
}"
答案:
B
A.代码编译失败,因为无异常抛出
B.代码编译失败,因为未导入IOException异常类
C."输出BeforeTry
AttheEnd"
D."输出InsideCatch
AttheEnd"
30.关于try…catch…finally结构,描述正确的是些?
答案:
AC
A.可以有多个catch
B.只能有一个catch
C.可以没有catch
D.finally必须有
31."当fragile()方法抛出一个IllegalArgumentException异常时,下列代码的运行结果是什么?
publicstaticvoidmain(String[]args)throwsIOException{
try{
fragile();
}catch(NullPointerExceptione){
System.out.println(""NullPointerExceptionthrown"");
}catch(Exceptione){
System.out.println(""Exceptionthrown"");
}finally{
System.out.println(""Donewithexceptions"");
}
System.out.println(""myMethodisdone"");
}
}"
答案:
A.输出NullPointerExceptionthrown
B.输出Exceptionthrown
C.输出DonewithException
D.输出myMethodisdone
32."现有如下代码:
publicclassExample{
publicstaticvoidmain(String[]args){
try{
intx=Integer.parseInt(""42a"");
//插入代码处
System.out.println(""oops"");
}
}
}
在插入代码处插入哪些语句可以在运行后输出oops?
"
答案:
C
A.}catch(IllegalArgumentExceptione){(非法参数异常)
B.}catch(IllegalStateExceptionc){
C.}catch(NumbelFormatExceptionn){
D.}catch(ClassCastExceptionc){
33."下列代码的执行结果是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
inti=1,j=1;
try{
i++;
j--;
if(i==j){
j++;
}
}catch(ArithmeticExceptione){
System.out.println(0);
}catch(ArrayIndexOutOfBoundsExceptione){
System.out.println
(1);
}catch(Exceptione){
System.out.println
(2);
}finally{
System.out.println(3);
}
System.out.println(4);
}
}"
答案:
CD
A.输出1
B.输出2
C.输出3
D.输出4
34.以下哪个方法用于计算平方根?
答案:
B
A.squareRoot()
B.sqrt()
C.root()
D.sqr()
35.以下哪些描述是正确的?
答案:
CD
A.try语句块后必须至少存在一个catch语句块
B.try语句块后可以存在不限数量的finally语句块
C.try语句块后必须至少存在一个catch语句块或finally语句块
D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前
36.Java语言中异常的分类是哪项?
答案:
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
37."如下代码执行后的输出结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
try{
thrownewException();
}catch(Exceptione){
try{
thrownewException();
}catch(Exceptione2){
System.out.println(""inner"");
}
System.out.println(""middle"");
}
System.out.println(""out"");
}
}"
答案:
D
A.innerouter
B.middleouter
C.innermiddleouter
D.编译失败
38."现有如下代码:
publicclassExample{
publicstaticvoidmain(String[]args){//a
newExample().topGo();
}
voidtopGo(){//b
middleGo();
}
voidmiddleGo(){//c
go();
System.out.println(""latemiddle"");
}
voidgo(){//d
thrownewException();
}
}
为了使代码能够编译通过,需要在哪个地方加入声明throwsException?
"
答案:
B
A.d
B.c和d
C.b、c和d
D.a、b、c和d
39.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?
答案:
C
A.只有当一个catch语句获得执行后,finally语句才获得执行
B.只有当catch语句未获得执行时,finally语句才获得执行
C.如果有finally语句,return语句将在finally语句执行完毕后才会返回
D.只有当异常抛出时,finally语句才获得执行
40."关于以下代码,说法正确的是?
classExample{
publicstaticvoidmain(S