精选新版JAVASE综合考核题库188题含答案.docx
《精选新版JAVASE综合考核题库188题含答案.docx》由会员分享,可在线阅读,更多相关《精选新版JAVASE综合考核题库188题含答案.docx(65页珍藏版)》请在冰点文库上搜索。
精选新版JAVASE综合考核题库188题含答案
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1.以下哪个方法用于计算平方根?
答案:
B
A.squareRoot()
B.sqrt()
C.root()
D.sqr()
2."下面代码的执行结果是?
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.编译失败
3."关于以下代码,说法正确的是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
if(args[0]==""hello""){
thrownewIOException();
}
}
}"
答案:
A
A.代码编译成功
B.代码编译失败,因为main()方法是入口方法,不能抛出异常
C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出
D.代码编译失败,因为字符串应该用equals方法判定一致性
4."给出以下代码:
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
try{
methodA();
}catch(IOExceptione){
System.out.println(""caughtIOException"");
}catch(Exceptione){
System.out.println(""caughtException"");
}
}
}
如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?
"
答案:
A.无内容输出
B.代码编译失败
C.输出caughtIOException
D.输出caughtException
5."给出以下代码,执行结果是?
classExample{
publicstaticvoidmain(String[]args)throwsIOException{
aMethod();
}
staticvoidaMethod(){
try{
System.out.println(""Try"");
return;
}catch(Exceptione){
System.out.println(""Catch"");
}finally{
System.out.println(""Finally"");
}
}
}"
答案:
A.代码编译成功,但运行期间抛出异常
B.代码便以失败,因为return语句错误
C.输出Try和Finally
D.输出Try
6."以下代码中,如果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.以上都不对
7."以下代码执行结果是什么?
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
8."以下代码的输出结果是什么?
选择所有的正确答案。
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
9.Java语言中异常的分类是哪项?
答案:
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
10.下列关于Math类说法错误的是
答案:
A.java.lang.Math类是final类,因此不能被其他类继承
B.java.lang.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象
C.java.lang.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用
D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
11."下列代码执行后的输出是哪项?
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]
12.定义在Math类上的round(doubled)方法的返回值类型是什么?
答案:
A.char
B.int
C.long
D.double
13.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?
答案:
C
A.raiseServiceException
B.thrownewServiceException()
C.throwServiceException
D.throwsServiceException
14.调用Math.random()方法最有可能输出以下哪些结果?
答案:
D
A.-0.12和0.56E3
B.0.12和1.1E1
C.-23.45和0.0
D.0.356和0.03
15."以下代码的输出结果是什么?
publicclassExample{
publicstaticvoidmain(String[]args){
System.out.println(Math.round(Float.MAX_VALUE));
}
}"
答案:
B
A.输出Integer.MAX_VALUE
B.输出一个最接近Float.MAX_VALUE的整数
C.编译失败
D.运行时输出异常信息
16."以下代码的运行结果是什么?
publicclassExample{
publicstaticvoidmain(String[]args){
doubled1=-0.5;
System.out.println(""Ceild1=""+Math.ceil(d1));
System.out.println(""Floord1=""+Math.floor(d1));
}
}
"
答案:
B
A.输出Ceild1=-0.0Floord1=-1.0
B.输出Ceild1=0.0Floord1=-1.0
C.输出Ceild1=-0.0Floord1=-0.0
D.输出Ceild1=0.0Floord1=0.0
17."给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?
publicclassExample{
publicstaticvoidmain(String[]args){
doubled=-11.1;
doubled1=method(d);
System.out.println(d1);
}
}"
答案:
A
A.floor()
B.ceil()
C.round()
D.abs()
18."给出以下代码,请问在程序的第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]));
19.下列哪些项是泛型的优点?
答案:
A
A.不用向下强制类型转换
B.代码容易编写
C.类型安全
D.运行速度快
20.以下哪些有关Vector类的描述是正确的?
答案:
C
A.该类是个public类
B.该类是个final类
C.该类实现了List接口
D.该类可以序列化
21.以下哪些集合接口支持重复元素存在?
答案:
B
A.Collection
B.List
C.Map
D.Set
22.以下哪些描述是正确的?
答案:
C
A.native关键字表明修饰的方法是由其他非Java语言编写的
B.能够出现在Java源文件中import语句前的只有注释语句(还可以有包)
C.接口中定义的方法默认是public和abstract的,不能被private或protected修饰
D.构造器只能被public或protected修饰(还有privatepublic)
23.以下哪个方法是Math类中定义的?
答案:
A.absolute()
B.log()
C.cosine()
D.sine()
24."对以下两个代码片段说法正确的是?
代码片段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抛出异常
25.以下哪些方法在Class类中定义?
答案:
A.getConstructors()
B.getPrivateMethods()
C.getDeclaredFields()
D.getImports()
26.关于类继承的说法,正确的是()
答案:
B
A.Java类允许多继承
B.Java接口允许多继承
C.接口和类都允许多继承
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{
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
30.下列属于非受检异常(运行时异常)的是哪项?
答案:
A
A.IOException
B.NullPointerException
C.OutOfMemoryError
D.
31.以下说法错误的是?
答案:
C
A.Java中接口不能被private或Protected修饰符修饰
B.Java中一个类可以实现多个接口,但是只能继承一个父类
C.接口中定义的成员变量,即使不说明,默认均是public\static\final的
D.final\static\native关键字不能修饰接口,
32.请问以下哪个程序代码体现了对象之间的isa关系?
答案:
A."publicinterfaceColor{
}
publicclassShape{
privateColorcolor;
}"
B."publicinterfaceComponent{
}
publicclassCpmtaomerimplementsComponent{
privateComponent[]children;
}"
C."publicclassSpecies{
}
publicclassAnimal{
privateSpeciesspecies;
}"
D."publicclassAnimal{
publicinterfaceSpecies{
}
privateSpeciesspecies;
}"
33."给出以下代码,改程序的执行结果是?
interfaceBase{
intk=0;
}
publicclassExampleimplementsBase{
publicstaticvoidmain(String[]args){
inti;
Exampleexm=newExample();
i=exm.k;
i=Example.k;
i=Base.k;
System.out.println(i);
}
}"
答案:
D
A.无内容输出
B.代码编译失败
C.代码运行时输出异常信息
D.打印输出0
34."现有如下代码:
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
35.Java语言中异常的分类是哪项?
答案:
C
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
36."现有代码如下:
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
37."现有如下代码:
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.编译失败
38.关于异常处理,说法错误的是?
答案:
C
A.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一
B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面
C.一个方法可以抛出多个异常,方法的返回值也能够是异常
D.Throwable是所有异常的超类
39.关于try…catch…finally结构,描述正确的是些?
答案:
AC
A.可以有多个catch
B.只能有一个catch
C.可以没有catch
D.finally必须有
40."当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