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]));
10.以下哪些是Collection接口的子接口?
答案:
BD
A.Dictionary
B.List
C.Map
D.Set
11.以下哪些是定义在java.io包中的抽象类?
答案:
A.InputStream
B.PrintStream
C.Reader
D.FileInputStream
12.以下哪些集合接口支持重复元素存在?
答案:
B
A.Collection
B.List
C.Map
D.Set
13."现有如下代码:
publicclassExample{
publicstaticvoidmain(String[]args){
try{
System.out.println(""before"");
doRisyThing();
System.out.println(""after"");
}catch(Exceptione){
System.out.println(""catch"");
}
System.out.println(""done"");
}
publicstaticvoiddoRisyThing()throwsException{
//thiscodereturnsunlessitthrowsanException
}
}
该代码可能的执行结果有哪些?
"
答案:
A.beforecatch
B.beforeafterdone
C.beforecatchdone
D.beforeaftercatch
14.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?
答案:
B
A.ArrayListmyList=newObject()
B.ListmyList=newArrayList()
C.ArrayListmyList=newList()
D.ListmyList=newList()
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.以下哪些语句用于创建一个Map实例?
答案:
D
A.Mapm=newMap();
B.Mapm=newMap(initcapacity,incrementcapacity);
C.Mapm=newMap(newCollection());
D.以上都不对
17."以下代码执行结果是?
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
18."现有如下类型:
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
19."现有:
publicclassExample{
publicstaticvoidmain(String[]args){
//插入代码处
c.put(""X"",123);
}
}
下列哪些插入到插入代码处能够正常编译?
"
答案:
A.Mapc=newSortedMap();
B.HashMapc=newHashMap();
C.SortedMapc=newTreeMap();
D.Mapc=newLinkedHashMap();
20.以下哪些类提供了创建一个目录的方法?
答案:
A
A.File
B.DataOutput
C.Directory
D.FileDescriptor
21.现有intx=reader.read(),下列哪一项正确?
答案:
A.reader不是FileReader或者BufferedReader类型
B.reader可以使FileReader或者BufferedReader
C.reader可以使FileReader类型,但不能使BufferedReader类型
D.reader可以使BufferedReader类型,但不能使FileReader类型
22."现有代码:
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.编译失败
23.以下哪些有关Vector类的描述是正确的?
答案:
C
A.该类是个public类
B.该类是个final类
C.该类实现了List接口
D.该类可以序列化
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{
doublex=64.0;
doubley=0.0;
System.out.println(x%y);
}catch(Exceptione){
System.out.println(""Exception"");
}
}
}"
答案:
D
A.编译失败
B.输出Exception
C.输出Infinity
D.输出NaN
27."关于以下代码,说法正确的是?
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"
28.关于try…catch…finally结构,描述正确的是些?
答案:
AC
A.可以有多个catch
B.只能有一个catch
C.可以没有catch
D.finally必须有
29."当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
30."现有如下代码:
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){
31."下列代码的执行结果是?
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
32.以下哪些是catch语句能够捕获处理的异常?
答案:
AC
A.Throwable
B.Error
C.Exception
D.String
33.以下哪些描述是正确的?
答案:
CD
A.try语句块后必须至少存在一个catch语句块
B.try语句块后可以存在不限数量的finally语句块
C.try语句块后必须至少存在一个catch语句块或finally语句块
D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前
34."以下代码的输出结果是什么?
选择所有的正确答案。
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
35."下列代码的运行结果是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
try{
return;
}finally{
System.out.println(""Finally"");
}
}
}"
答案:
B
A.无内容输出
B.输出Finally
C.代码编译失败
D.输出异常信息
36."下列代码的执行结果是?
classExample{
privatevoidmethod1()throwsException{
thrownewRuntimeException();
}
publicvoidmethod2(){
try{
method1();
}catch(RuntimeExceptione){
System.out.println(""CaughtRuntimeException"");
}catch(Exceptione){
System.out.println(""CaughtException"");
}
}
publicstaticvoidmain(String[]args)throwsIOException{
Examplea=newExample();
a.method2();
}
}"
答案:
A.代码编译失败
B.输出CaughtRuntimeException
C.输出CaughtException
D.输出CaughtRuntimeException和CaughtException
37.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?
答案:
D
A.throw
B.catch
C.finally
D.throws
38."如下代码执行后的输出结果是?
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.编译失败
39."现有如下代码:
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
40."下面代码的执行结果是?
classExampleextendsUtils{
publicstaticvoidmain(String[]args){
try{
System.out.print(newExample().getlnt(""42""));
}catch(Exceptione){
System.out.println(""Exc"");
}
}
intgetlnt(Stringarg)throwsException{
returnInteger.parseInt(arg);
}
}
classUtils{
intgetlnt(){
return42;
}
}"
答案:
B
A.NFExc
B.42
C.42NFExc
D.编译失败
41.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?
答案:
C
A.只有当一个catch语句获得执行后,finally语句才获得执行
B.只有当catch语句未获得执行时,finally语句才获得执行
C.如果有finally语句,return语句将在finally语句执行完毕后才会返回
D.只有当异常抛出时,finally语句才获得执行
42."关于以下代码,说法正确的是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
System.out.println(""BeforeTry"");
try{
}catch(java.io.IOExceptione){
System.out.println(""InsideCatch"");
}
System.out.println(""AttheEnd"");
}
}"
答案:
A.代码编译失败,因为无异常抛出
B.代码编译失