精编JAVASE综合测试题库188题含参考答案.docx
- 文档编号:14387349
- 上传时间:2023-06-23
- 格式:DOCX
- 页数:78
- 大小:35.13KB
精编JAVASE综合测试题库188题含参考答案.docx
《精编JAVASE综合测试题库188题含参考答案.docx》由会员分享,可在线阅读,更多相关《精编JAVASE综合测试题库188题含参考答案.docx(78页珍藏版)》请在冰点文库上搜索。
精编JAVASE综合测试题库188题含参考答案
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1."现有:
list是一个合法的集合引用
getCollection()返回一个合法集合的引用,以下语句哪些是合法的?
"
答案:
C
A.for(Objecto:
list)
B.for(Objecto:
getCollection())
C.for(Objecto:
list.iterator())
D.for(IteratorI;list.iterator();i.hasNext())
2.下列关于Math类说法错误的是
答案:
A.java.lang.Math类是final类,因此不能被其他类继承
B.java.lang.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象
C.java.lang.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用
D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
3.定义在Math类上的round(doubled)方法的返回值类型是什么?
答案:
A.char
B.int
C.long
D.double
4.调用Math.random()方法最有可能输出以下哪些结果?
答案:
D
A.-0.12和0.56E3
B.0.12和1.1E1
C.-23.45和0.0
D.0.356和0.03
5."以下代码的输出结果是什么?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.round(Float.MAX_VALUE));
}
}"
答案:
B
A.输出Integer.MAX_VALUE
B.输出一个最接近Float.MAX_VALUE的整数
C.编译失败
D.运行时输出异常信息
6."以下代码执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.min(Float.NaN,Float.POSITIVE_INFINITY));
}
}"
答案:
A
A.输出NaN
B.打印输出Infinity
C.运行时异常,因为NaN不是有效的参数
D.运行时异常,因为Infinity不是有效的参数
7.下列哪些项是泛型的优点?
答案:
A
A.不用向下强制类型转换
B.代码容易编写
C.类型安全
D.运行速度快
8.以下哪些有关Vector类的描述是正确的?
答案:
C
A.该类是个public类
B.该类是个final类
C.该类实现了List接口
D.该类可以序列化
9.以下哪些集合接口支持重复元素存在?
答案:
B
A.Collection
B.List
C.Map
D.Set
10.表示键值对概念的接口是哪项?
答案:
D
A.Set
B.List
C.Collection
D.Map
11.以下哪些描述是正确的?
答案:
A.Writer类可以使用不同的字符编码向输出流写入字符
B.Writer类可以向输出流写入Unicode字符
C.Writer类提供向输出流写入任意Java基本数据类型的方法
D.Writer类提供向输出流写入引用数据类型的方法
12.创建一个只能存放String的泛型ArrayList的语句是哪项?
答案:
B
A.ArrayList
B.ArrayList
C.ArrayListal=newArrayList
D.ArrayList
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."现有:
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
15."以下代码执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
TreeMap
map.put(""one"",""1"");
map.put(""two"",""2"");
map.put(""three"",""3"");
displayMap(map);
}
staticvoiddisplayMap(TreeMapmap){
Collection
Iterator
while(i.hasNext()){
Objecto=i.next();
System.out.print(o.toString());
}
}
}"
答案:
A.onetwothree
B.123
C.one=1three=3two=2
D.onethreetwo
16.以下哪些类提供了创建一个目录的方法?
答案:
A
A.File
B.DataOutput
C.Directory
D.FileDescriptor
17.以下说法正确的是()
答案:
A.RandomAccessFile类是File类的子类
B.FileWriter类提供有操作基本数据类型的方法
C.RandomAccessFile类提供有删除磁盘文件的方法
D.File类提供有删除磁盘文件的方法
18."现有:
f是一个File类实例的合法引用
fr是一个FileReader类实例的合法引用
br是一个BufferedReader类实例的合法引用
如下代码:
Stringline=null;
//插入代码处
System.out.println(line);
}
哪一行代码插入到插入代码处将循环一次输出文本文件的一行?
"
答案:
A.while((line=f.read())!
=null){
B.while((line=fr.read())!
=null){
C.while((line=br.read())!
=null){
D.while((line=br.readLine())!
=null){
19."现有:
Strings=""writealinetoafile"";
w.print(s+""\n"");
哪一个是对的?
"
答案:
A.w既可以是PrintWriter类型,也可以是BufferedWriter类型
B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型
C.w可以是PrintWriter类型,但不可以是BufferedWriter类型
D.w既可以是BufferedWriter类型,也可以是PrintWriter类型
20.以下哪些是FileOutputSteram类的正确构造形式?
答案:
A.FileOutputStream(FileDescriptorfd)
B.FileOutputStream(Stringn,booleana)
C.FileOutputStream(booleana)
D.FileOutputStream(Filef)
21.以下哪些是定义在java.io包中的抽象类?
答案:
A.InputStream
B.PrintStream
C.Reader
D.FileInputStream
22.Java语言中异常的分类是哪项?
答案:
C
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
23.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?
答案:
B
A.ArrayListmyList=newObject()
B.ListmyList=newArrayList()
C.ArrayListmyList=newList()
D.ListmyList=newList()
24.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?
答案:
C
A.raiseServiceException
B.thrownewServiceException()
C.throwServiceException
D.throwsServiceException
25.以下哪些方法在Class类中定义?
答案:
A.getConstructors()
B.getPrivateMethods()
C.getDeclaredFields()
D.getImports()
26."对以下两个代码片段说法正确的是?
代码片段1:
inta=3;
intb=0;
intc=a/b;
代码片段2:
floata=3.0f;
floatb=0.0f;
floatc=a/b;"
答案:
C
A.执行两端代码都会抛出异常
B.执行两段代码都无异常抛出
C.执行两段代码,只有代码片段1抛出异常
D.执行两段代码,只有代码片段2抛出异常
27."下列代码执行后的结果是?
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
28."现有如下代码:
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.编译失败
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."当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
31."现有如下代码:
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){
32."下列代码的执行结果是?
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
33.以下哪些是catch语句能够捕获处理的异常?
答案:
AC
A.Throwable
B.Error
C.Exception
D.String
34.Java语言中异常的分类是哪项?
答案:
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
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{
voidtopGo(){
try{
middleGo();
}catch(Exceptione){
System.out.println(""catch"");
}
}
voidmiddleGo()throwsException{
go();
System.out.println(""latemiddle"");
}
voidgo()throwsException{
thrownewException();
}
publicstaticvoidmain(String[]args){
Exampleexample=newExample();
example.topGo();
}
}
该代码的执行结果是?
"
答案:
B
A.输出latemiddle
B.输出catch
C.输出latemiddlecatch
D.输出catchlatemiddle
39."如下代码执行后的输出结果是?
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.编译失败
40."现有如下代码:
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
41.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?
答案:
C
A.只有当一个catch语句获得执行后,finally语句才获得执行
B.只有当catch语句未获得执行时,finally语句才获得执行
C.如果有finally语句,return语句将在f
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 精编 JAVASE 综合测试 题库 188 参考答案