精选最新版JAVASE综合完整考试题库188题含参考答案.docx
《精选最新版JAVASE综合完整考试题库188题含参考答案.docx》由会员分享,可在线阅读,更多相关《精选最新版JAVASE综合完整考试题库188题含参考答案.docx(77页珍藏版)》请在冰豆网上搜索。
精选最新版JAVASE综合完整考试题库188题含参考答案
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1."以下代码执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.min(Float.NaN,Float.POSITIVE_INFINITY));
}
}"
答案:
A
A.输出NaN
B.打印输出Infinity
C.运行时异常,因为NaN不是有效的参数
D.运行时异常,因为Infinity不是有效的参数
2."关于以下代码,说法正确的是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
if(args[0]==""hello""){
thrownewIOException();
}
}
}"
答案:
A
A.代码编译成功
B.代码编译失败,因为main()方法是入口方法,不能抛出异常
C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出
D.代码编译失败,因为字符串应该用equals方法判定一致性
3."关于以下代码,说法正确的是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
System.out.println(""BeforeTry"");
try{
}catch(java.io.IOExceptione){
System.out.println(""InsideCatch"");
}
System.out.println(""AttheEnd"");
}
}"
答案:
A.代码编译失败,因为无异常抛出
B.代码编译失败,因为未导入IOException异常类
C."输出BeforeTry
AttheEnd"
D."输出InsideCatch
AttheEnd"
4."以下代码中,如果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.以上都不对
5."以下代码执行结果是什么?
classExample{
publicstaticStringoutput="""";
publicstaticvoidfoo(inti){
try{
if(i==1){
thrownewException();
}
output+=""1"";
}catch(Exceptione){
output+=""2"";
return;
}finally{
output+=""3"";
}
output+=""4"";
}
publicstaticvoidmain(String[]args)throwsIOException{
foo(0);
foo
(1);
System.out.println(output);
}
}"
答案:
A.无内容输出
B.代码编译失败
C.输出13423
D.输出14323
6."关于以下代码正确的说法是:
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行编译错误
7."下列代码的执行结果是?
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
8.Java语言中异常的分类是哪项?
答案:
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
9.下列关于Math类说法错误的是
答案:
A.java.lang.Math类是final类,因此不能被其他类继承
B.java.lang.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象
C.java.lang.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用
D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
10.定义在Math类上的round(doubled)方法的返回值类型是什么?
答案:
A.char
B.int
C.long
D.double
11."以下代码的执行结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
Filef=newFile(""c:
\\large.txt"");
}
}"
答案:
A.large.txt文件在本地硬盘上被创建
B.在Unix系统上运行失败,因为路径分割符不正确
C.large.txt文件在本地硬盘上没有被创建
D.如果large.txt文件已经存在,则一个异常被抛出
12."给出以下代码,请问在程序的第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;a6.
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]));
13.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?
答案:
D
A.throw
B.catch
C.finally
D.throws
14.以下哪些是Collection接口的子接口?
答案:
BD
A.Dictionary
B.List
C.Map
D.Set
15.以下哪些有关Vector类的描述是正确的?
答案:
C
A.该类是个public类
B.该类是个final类
C.该类实现了List接口
D.该类可以序列化
16.表示键值对概念的接口是哪项?
答案:
D
A.Set
B.List
C.Collection
D.Map
17.List接口的特点是哪项?
答案:
C
A.不允许重复元素,元素有顺序
B.允许重复元素,元素无顺序
C.允许重复元素,元素有顺序
D.不允许重复元素,元素无顺序
18.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?
答案:
B
A.ArrayListmyList=newObject()
B.ListmyList=newArrayList()
C.ArrayListmyList=newList()
D.ListmyList=newList()
19."下列代码执行后的输出是哪项?
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]
20."现有:
list是一个合法的集合引用
getCollection()返回一个合法集合的引用,以下语句哪些是合法的?
"
答案:
C
A.for(Objecto:
list)
B.for(Objecto:
getCollection())
C.for(Objecto:
list.iterator())
D.for(IteratorI;list.iterator();i.hasNext())
21."现有如下类型:
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
22.Java语言中异常的分类是哪项?
答案:
A
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
23."以下代码的运行结果是什么?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.min(0.0,-0.0));
}
}"
答案:
C
A.代码编译失败
B.输出0.0
C.输出-0.0
D.代码编译成功,但运行时输出异常信息
24.Java语言中异常的分类是哪项?
答案:
C
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
25.以下哪些方法在Class类中定义?
答案:
A.getConstructors()
B.getPrivateMethods()
C.getDeclaredFields()
D.getImports()
26.以下有关java.lang.Exception异常类的正确描述有?
答案:
B
A.该类是一个公共类
B.该类是Throwable类的子类
C.该类实现了Throwable接口
D.该类可以序列化
27."对以下两个代码片段说法正确的是?
代码片段1:
inta=3;
intb=0;
intc=a/b;
代码片段2:
floata=3.0f;//Infinity(无穷大)
floatb=0.0f;
floatc=a/b;"
答案:
C
A.执行两端代码都会抛出异常
B.执行两段代码都无异常抛出
C.执行两段代码,只有代码片段1抛出异常
D.执行两段代码,只有代码片段2抛出异常
28."下列代码执行后的结果是?
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
29."下列代码执行后的结果是?
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
30."下列代码执行后的结果是?
publicclassExample{
publicstaticvoidmain(String[]args){
try{
System.out.println(Float.NaN==Float.NaN);
System.out.println(Float.POSITIVE_INFINITY==Float.POSITIVE_INFINITY);
}catch(Exceptione){
System.out.println(""Exception"");
}
}"
答案:
D
A.输出+G20:
J20falsefalse
B.输出Exception
C.输出truetrue
D.输出falsetrue
31.下列属于非受检异常(运行时异常)的是哪项?
答案:
A
A.IOException
B.NullPointerException
C.OutOfMemoryError
D.
32.以下说法错误的是?
答案:
C
A.Java中接口不能被private或Protected修饰符修饰
B.Java中一个类可以实现多个接口,但是只能继承一个父类
C.接口中定义的成员变量,即使不说明,默认均是public\static\final的
D.final\static\native关键字不能修饰接口,
33.请问以下哪个程序代码体现了对象之间的isa关系?
答案:
A."publicinterfaceColor{
}
publicclassShape{
privateColorcolor;
}"
B."publicinterfaceComponent{
}
publicclassCpmtaomerimplementsComponent{
privateComponent[]children;
}"
C."publicclassSpecies{
}
publicclassAnimal{
privateSpeciesspecies;
}"
D."publicclassAnimal{
publicinterfaceSpecies{
}
privateSpeciesspecies;
}"
34."下面代码的执行结果是?
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.编译失败
35."现有以下代码:
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;"
36."如下代码执行后的输出结果是?
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.编译失败
37."对以下两个代码片段说法正确的是?
代码片段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抛出异常
38."现有如下代码:
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.编译失败
39.关于异常处理,说法错误的是?
答案:
C
A.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一
B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面
C.一个方法可以抛出多个异常,方法的返回值也能够是异常
D.Throwable是所有异常的超类
40."关于以下代码,说法正确的是?
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"
41."当fragile()方法抛出一个IllegalArgumentException异常时,下列代码的运行结果是什么?
publicstaticvoidmain(String[]args)throwsIOExce