1、精选新版JAVASE综合模拟题库188题含参考答案2020年JAVASE综合考试试题库188题含答案一、选择题1以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()2请问以下哪些关于trycatchfinally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行3关于以下
2、代码,说法正确的是?class Example public static void main(String args) throws IOException System.out.println(Before Try); try catch (java.io.IOException e) System.out.println(Inside Catch); System.out.println(At the End); 答案:A.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C.输出Before TryAt the EndD.输出Inside CatchA
3、t the End4以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?class Example public static void main(String args) throws IOException try test(); System.out.println(Message1); catch (ArrayIndexOutOfBoundsException e) System.out.println(Message2); finally System.out.println(Message3); 答案:A.打印输出Message1B
4、.打印输出Message2C.打印输出Message3D.以上都不对5以下代码执行结果是什么?class Example public static String output = ; public static void foo(int i) try if (i = 1) throw new Exception(); output += 1; catch (Exception e) output += 2; return; finally output += 3; output += 4; public static void main(String args) throws IOExcep
5、tion foo(0); foo(1); System.out.println(output); 答案:A.无内容输出B.代码编译失败C.输出13423D.输出143236关于以下代码正确的说法是:1.public class Example 2. int x = 0;3.4. public Example(int inVal) throws Exception 5. if (inVal != this.x) 6. throw new Exception(Invalid input);7. 8. 9.10. public static void main(String args) 11. Ex
6、ample t = new Example(4);12. 13.答案:A.代码在第1行编译错误B.代码在第4行编译错误C.代码在第6行编译错误D.代码在第11行编译错误7下列代码的执行结果是?class Example private void method1() throws Exception throw new RuntimeException(); public void method2() try method1(); catch (RuntimeException e) System.out.println(Caught Runtime Exception); catch (Exc
7、eption e) System.out.println(Caught Exception); public static void main(String args) throws IOException Example a = new Example(); a.method2(); 答案:A.代码编译失败B.输出Caught Runtime ExceptionC.输出Caught ExceptionD.输出Caught Runtime Exception和Caught Exception8以下代码的输出结果是什么?选择所有的正确答案。class Example public static
8、void main(String args) throws IOException for (int i = 0; i 10; i+) try try if (i % 3 = 0) throw new Exception(E0); System.out.println(i);break; catch (Exception inner) i *= 2; if (i % 3 = 0) throw new Exception(E1); finally +i; catch (Exception outer) i += 3; finally -i; 答案:A.4B.5C.6D.79Java语言中异常的分
9、类是哪项?答案: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下列代码执行后的输出是哪项?public class Example public sta
10、tic void main(String args) List al = new ArrayList(); al.add(1); al.add(2); al.add(2); al.add(3); System.out.println(al); 答案:A.1,2,3B.1,2,3,3C.1,2,2,3D.2,1,3,212定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double13如下代码执行后的输出结果是?public class Example public static void main(String args)
11、try throw new Exception(); catch (Exception e) try throw new Exception(); catch (Exception e2) System.out.println(inner); System.out.println(middle); System.out.println(out); 答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败14调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.
12、45和0.0D.0.356和0.0315以下代码的运行结果是什么?public class Example public static void main(String args) double d1 = -0.5; System.out.println(Ceil d1= + Math.ceil(d1); System.out.println(Floor d1= + Math.floor(d1); 答案:BA.输出Ceil d1=-0.0 Floor d1=-1.0B.输出Ceil d1=0.0 Floor d1=-1.0C.输出Ceil d1=-0.0 Floor d1=-0.0D.输出Ce
13、il d1=0.0 Floor d1=0.016给出以下代码,为了结果输出-12.0,方法method(d)应为以下哪个方法?public class Example public static void main(String args) double d = -11.1; double d1 = method(d); System.out.println(d1); 答案: AA.floor()B.ceil()C.round()D.abs()17下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快18以下哪些是Collection接口的子接口?答
14、案:BDA.DictionaryB.ListC.MapD.Set19以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化20以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set21List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序22以下关于Error和Exception类的描述正确的是?答案:AA.Error类和Exception类都是Throwable类的
15、子类B.Error类是一个final类,而Exception类是一个非final类C.Exception类是一个final类,而Error类是一个非final类D.Error类和Exception类都实现了Throwable接口23以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()24关于异常处理,说法错误的是?答案:CA.trycatchfinally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若c
16、atch中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类25以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26下列代码执行后的结果是?public class Example public static void main(String args) try double x = 64.0; double y = 0.0; System.out.p
17、rintln(x % y); catch (Exception e) System.out.println(Exception); 答案:DA.编译失败B.输出ExceptionC.输出InfinityD.输出NaN27下列代码执行后的结果是?public class Example public static void main(String args) try double x = 64.0; double y = 0.0; System.out.println(x % y = x % y); catch (Exception e) System.out.println(Exception
18、); 答案:DA.编译失败B.运行时抛出异常C.打印输出trueD.打印输出false28下列代码执行后的结果是?public class Example public static void main(String args) try System.out.println(Float.NaN = Float.NaN); System.out.println(Float.POSITIVE_INFINITY=Float.POSITIVE_INFINITY); catch (Exception e) System.out.println(Exception); 答案:DA.输出+G20:J20fa
19、lse falseB.输出ExceptionC.输出true trueD.输出false true29下列属于非受检异常(运行时异常)的是哪项?答案:AA.IOExceptionB.NullPointerExceptionC.OutOfMemoryErrorD.30以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是publicstaticfinal的D.finalstaticnative关键字不能修饰接口,31给出以下代码,改程序的执行结果是?in
20、terface Base int k = 0;public class Example implements Base public static void main(String args) int i; Example exm = new Example(); i = exm.k; i = Example.k; i = Base.k; System.out.println(i); 答案:DA.无内容输出B.代码编译失败C.代码运行时输出异常信息D.打印输出032现有以下代码:interface W class Z implements W class X extends Z class Y
21、 extends Z 下列哪些代码段是正确的?答案:A.X x=new X();Y y=new Y();Z z=new Z();y=(Y)x;B.X x=new X();Y y=new Y();Z z=new Z();x=(X)y;C.X x=new X();Y y=new Y();Z z=new Z();Z=(Z)x;D.X x=new X();Y y=new Y();Z z=new Z();W w=(W)x;33对以下两个代码片段说法正确的是?代码片段1: int a = 3; int b = 0; int c = a / b;代码片段2:float a = 3.0f;float b =
22、0.0f;float c = a / b;答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常34下面代码的执行结果是?class Example extends Utils public static void main(String args) try System.out.print(new Example().getlnt(42); catch (Exception e) System.out.println(Exc); int getlnt(String arg) throws Excepti
23、on return Integer.parseInt(arg); class Utils int getlnt() return 42; 答案:BA.NFExcB.42C.42NFExcD.编译失败35现有如下代码:public class Example extends Utils public static void main(String args) try System.out.println(new Example().getInt(42); catch (NumberFormatException e) System.out.println(NFExc); int getInt(S
24、tring arg) throws NumberFormatException return Integer.parseInt(arg); class Utils int getInt(String arg) return 42; 该代码执行的结果是?答案:BA.NFExcB.42C.42NFExcD.编译失败36现有如下代码:public class Example public static void main(String args) / a new Example().topGo(); void topGo() / b middleGo(); void middleGo() / c g
25、o(); System.out.println(late middle); void go() / d throw new Exception(); 为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?答案:BA.dB.c和dC.b、c和dD.a、b、c和d37关于以下代码,说法正确的是?class Example public static void main(String args) throws IOException System.out.println(Before Try); try catch (Throwable e) System.out.prin
26、tln(Inside Catch); System.out.println(At the End); 答案:BA.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C.输出Before TryAt the EndD.输出Inside CatchAt the End38关于trycatchfinally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有39现有如下代码:public class Example public static void main(String args) tr
27、y int x=Integer.parseInt(42a); /插入代码处 System.out.println(oops); 在插入代码处插入哪些语句可以在运行后输出oops?答案:CA. catch (IllegalArgumentException e) (非法参数异常)B. catch (IllegalStateException c) C. catch (NumbelFormatException n) D. catch (ClassCastException c) 40以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String41以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1