最新版精选JAVASE综合完整题库188题含参考答案.docx
- 文档编号:27531936
- 上传时间:2023-07-02
- 格式:DOCX
- 页数:81
- 大小:36.03KB
最新版精选JAVASE综合完整题库188题含参考答案.docx
《最新版精选JAVASE综合完整题库188题含参考答案.docx》由会员分享,可在线阅读,更多相关《最新版精选JAVASE综合完整题库188题含参考答案.docx(81页珍藏版)》请在冰豆网上搜索。
最新版精选JAVASE综合完整题库188题含参考答案
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1.以下哪些是Collection接口的子接口?
答案:
BD
A.Dictionary
B.List
C.Map
D.Set
2."下列代码的执行结果是?
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
3."以下代码的输出结果是什么?
选择所有的正确答案。
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
4.Java语言中异常的分类是哪项?
答案:
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
5.下列关于Math类说法错误的是
答案:
A.java.lang.Math类是final类,因此不能被其他类继承
B.java.lang.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象
C.java.lang.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用
D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
6.以下哪个方法是Math类中定义的?
答案:
A.absolute()
B.log()
C.cosine()
D.sine()
7.定义在Math类上的round(doubled)方法的返回值类型是什么?
答案:
A.char
B.int
C.long
D.double
8.以下哪个方法用于计算平方根?
答案:
B
A.squareRoot()
B.sqrt()
C.root()
D.sqr()
9.调用Math.random()方法最有可能输出以下哪些结果?
答案:
D
A.-0.12和0.56E3
B.0.12和1.1E1
C.-23.45和0.0
D.0.356和0.03
10."以下代码的运行结果是什么?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.min(0.0,-0.0));
}
}"
答案:
C
A.代码编译失败
B.输出0.0
C.输出-0.0
D.代码编译成功,但运行时输出异常信息
11."现有如下类型:
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
12."以下代码执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.min(Float.NaN,Float.POSITIVE_INFINITY));
}
}"
答案:
A
A.输出NaN
B.打印输出Infinity
C.运行时异常,因为NaN不是有效的参数
D.运行时异常,因为Infinity不是有效的参数
13."以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
try{
test();
System.out.println(""Message1"");
}catch(ArrayIndexOutOfBoundsExceptione){
System.out.println(""Message2"");
}finally{
System.out.println(""Message3"");
}
}
}"
答案:
A.打印输出Message1
B.打印输出Message2
C.打印输出Message3
D.以上都不对
14.以下哪些有关Vector类的描述是正确的?
答案:
C
A.该类是个public类
B.该类是个final类
C.该类实现了List接口
D.该类可以序列化
15.以下哪些集合接口支持重复元素存在?
答案:
B
A.Collection
B.List
C.Map
D.Set
16.List接口的特点是哪项?
答案:
C
A.不允许重复元素,元素有顺序
B.允许重复元素,元素无顺序
C.允许重复元素,元素有顺序
D.不允许重复元素,元素无顺序
17.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?
答案:
B
A.ArrayListmyList=newObject()
B.ListmyList=newArrayList()
C.ArrayListmyList=newList()
D.ListmyList=newList()
18.创建一个只能存放String的泛型ArrayList的语句是哪项?
答案:
B
A.ArrayList
B.ArrayList
C.ArrayListal=newArrayList
D.ArrayList
19."下列代码执行后的输出是哪项?
publicclassExample{
publicstaticvoidmain(String[]args){
List
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]
20."以下代码的执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
TreeSet
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
21."现有:
publicclassExample{
publicstaticvoidmain(String[]args){
TreeSet
s.add(""one"");
s.add(""two"");
//插入代码处
for(Strings2:
sorted){
System.out.print(s2+"""");
}
}
}
和四个代码片段:
s1:
SortedSetsorted=s.tailSet(s.first());
s2:
SortedSet
s3:
SortedSetsorted=(SortedSet)s.tailSet(s.first());
s4:
SortedSetsorted=(SortSet
分别插入到插入代码处,哪项可以编译?
"
答案:
A.S2
B.S2和S3
C.S2和S4
D.S2、S3和S4
22."下列代码执行后的结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
try{
doublex=64.0;
doubley=0.0;
System.out.println(x%y==x%y);
}catch(Exceptione){
System.out.println(""Exception"");
}
}
}"
答案:
D
A.编译失败
B.运行时抛出异常
C.打印输出true
D.打印输出false
23."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?
1.publicclassExample{
2.publicstaticvoidmain(String[]args){
3.doublex[]={10.2,9.1,8.7};
4.inti[]=newint[3];
5.for(inta=0;a 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])); 24."下列代码的执行结果是? 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 25.JavaUDP编程主要用到的两个类型是 答案: A.UDPSocket B.DatagramSocket C.UDPPacket D.DatagramPacket 26.以下说法错误的是? 答案: C A.Java中接口不能被private或Protected修饰符修饰 B.Java中一个类可以实现多个接口,但是只能继承一个父类 C.接口中定义的成员变量,即使不说明,默认均是public\static\final的 D.final\static\native关键字不能修饰接口, 27."现有以下代码: 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;" 28.Java语言中异常的分类是哪项? 答案: C A.运行时异常和异常 B.受检异常和非受检异常 C.错误和异常 D.错误和运行时异常 29."现有代码: 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.编译失败 30."下列代码执行后的结果是? 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 31."现有如下代码: 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.编译失败 32.关于异常处理,说法错误的是? 答案: C A.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一 B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面 C.一个方法可以抛出多个异常,方法的返回值也能够是异常 D.Throwable是所有异常的超类 33."关于以下代码,说法正确的是? 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" 34."现有如下代码: 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 35."现有如下代码: 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){ 36."关于以下代码正确的说法是: 1.publicclassExample{ 2.intx=0; 3. 4.publicExample(intinVal)throwsException{ 5.if(inVal! =this.x){ 6.thrownewException(""Invalidinput""); 7.} 8.} 9. 10.publicstaticvoidmain(String[]args){ 11.Examplet=newExample(4); 12.} 13.}" 答案: A.代码在第1行编译错误 B.代码在第4行编译错误 C.代码在第6行编译错误 D.代码在第11行编译错误 37.以下哪些是catch语句能够捕获处理的异常? 答案: AC A.Throwable B.Error C.Exception D.String 38.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项? 答案: C A.raiseServiceException B.thrownewServiceException() C.throwServiceException D.throwsServiceException 39."现有代码如下: publicclassExample{ voidtopGo(){ try{ middleGo(); }catch(Exceptione){ System.out.println(""catch""); } } voidmiddleGo()throwsException{ go(); System.out.println(""latemiddle""); } voidgo()throwsException{ thrownewException(); } publicstaticvoidmain(String[]args){ Exampleexample=newExample(); e
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新版 精选 JAVASE 综合 完整 题库 188 参考答案