新版精编JAVASE综合完整题库188题(含答案)
- 格式:doc
- 大小:210.00 KB
- 文档页数:55
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码的输出结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.round(Float.MAX_V ALUE));}}"答案:BA.输出Integer.MAX_V ALUEB.输出一个最接近Float.MAX_V ALUE的整数C.编译失败D.运行时输出异常信息2."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性3."关于以下代码,说法正确的是?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 End"D."输出Inside CatchAt the End"4."给出以下代码:class Example {public static void main(String[] args) throws IOException {try {methodA();} catch (IOException e) {System.out.println(""caught IOException"");}catch (Exception e) {System.out.println(""caught Exception"");}}}如果methodA()方法抛出一个IOException异常,则该程序的运行结果是什么?"答案:A.无内容输出B.代码编译失败C.输出caught IOExceptionD.输出caught Exception5."以下代码中,如果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.打印输出Message2C.打印输出Message3D.以上都不对6."以下代码执行结果是?public abstract class Example extends Base {public abstract void method();}class Base {public Base() throws IOException {throw new IOException();}}"答案:A.代码编译失败,因为非抽象类不能被扩展为抽象类B.代码编译失败,因为必须提供一个可以抛出或可以不抛出IOException异常的构造器C.代码编译失败,以in为必须提供一个可以抛出IOException异常或其子类的构造器D.代码编译成功7."关于以下代码正确的说法是: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. Example t = new Example(4);12. }13.}"答案:A.代码在第1行编译错误B.代码在第4行编译错误C.代码在第6行编译错误D.代码在第11行编译错误8."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");doRisyThing();System.out.println(""after"");} catch (Exception e) {System.out.println(""catch"");}System.out.println(""done"");}public static void doRisyThing() throws Exception{//this code returns unless it throws an Exception}}该代码可能的执行结果有哪些?"答案:A.before catchB.before after doneC.before catch doneD.before after catch9."下列代码的执行结果是?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 (Exception 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 Exception10."以下代码的输出结果是什么?选择所有的正确答案。
class Example {public static 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.711."现有:list是一个合法的集合引用getCollection()返回一个合法集合的引用,以下语句哪些是合法的?" 答案:CA.for(Object o : list)B.for(Object o : getCollection())C.for(Object o : list.iterator())D.for(Iterator I;list.iterator();i.hasNext())12.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()13."现有代码如下:public class Example {void topGo() {try {middleGo();} catch (Exception e) {System.out.println(""catch"");}}void middleGo() throws Exception {go();System.out.println(""late middle""); }void go() throws Exception {throw new Exception();}public static void main(String[] args) { Example example = new Example(); example.topGo();}}该代码的执行结果是?"答案:BA.输出late middleB.输出catchC.输出late middle catchD.输出catch late middle14."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息15."以下代码的运行结果是什么?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.输出Ceil d1=0.0 Floor d1=0.016."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?1.public class Example {2. public static void main(String[] args) {3. double x[] = { 10.2, 9.1, 8.7 };4. int i[] = new int[3];5. for (int a = 0; a < x.length; a++) {6.7. System.out.println(i[a]);8. }9. }10.}"答案:CA.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]));17."以下代码执行结果是?public class Example {public static void main(String[] args) {System.out.println(Math.min(Float.NaN, Float.POSITIVE_INFINITY)); }}"答案:AA.输出NaNB.打印输出InfinityC.运行时异常,因为NaN不是有效的参数D.运行时异常,因为Infinity不是有效的参数18.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set19.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化20.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set21.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序22.所有异常的父类是哪项?答案:AA.ThrowableB.ErrorC.RuntimeExceptionD.Exception23.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double24."现有如下代码: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(String arg) throws NumberFormatException{return Integer.parseInt(arg);}}class Utils {int getInt(String arg) {return 42;}}该代码执行的结果是?"答案:BA.NFExcB.42C.42NFExcD.编译失败25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26.以下有关ng.Exception异常类的正确描述有?答案:BA.该类是一个公共类B.该类是Throwable类的子类C.该类实现了Throwable接口D.该类可以序列化27."对以下两个代码片段说法正确的是?代码片段1:int a = 3;int b = 0;int c = a / b;代码片段2:float a = 3.0f; //Infinity(无穷大)float b = 0.0f;float c = a / b;"答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常28."下列代码执行后的结果是?public class Example {public static void main(String[] args) {try {double x = 64.0;double y = 0.0;System.out.println(x % y);} catch (Exception e) {System.out.println(""Exception"");}}}"A.编译失败B.输出ExceptionC.输出InfinityD.输出NaN29."下列代码执行后的结果是?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"");}}}"答案:DA.编译失败B.运行时抛出异常C.打印输出trueD.打印输出false30."下列代码执行后的结果是?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:J20false falseB.输出ExceptionC.输出true trueD.输出false true31.以下说法错误的是?A.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,32.请问以下哪个程序代码体现了对象之间的is a关系?答案:A."public interface Color {}public class Shape {private Color color;}"B."public interface Component {}public class Cpmtaomer implements Component {private Component[] children;}"C."public class Species{}public class Animal{private Species species;}"D."public class Animal{public interface Species{}private Species species;}"33."现有代码:public class Example {public static void main(String[] args) {try {System.out.print(Integer.parseInt(""forty""));} catch (RuntimeException e) {System.out.println(""Runtime"");}catch (NumberFormatException e) {System.out.println(""Number"");}}执行结果是什么?"答案:CA.输出NumberB.输出RuntimeC.输出40D.编译失败34.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行35."下列代码执行后的结果是?public class Example {public static void main(String[] args) {try {double x = 64.0;double y = 0.0;System.out.println(x % y);} catch (Exception e) {System.out.println(""Exception"");}}}"答案:DA.编译失败B.输出ExceptionC.输出InfinityD.输出NaN36."下面代码的执行结果是?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 Exception {return Integer.parseInt(arg);}}class Utils {int getlnt() {return 42;}}"答案:BA.NFExcB.42C.42NFExcD.编译失败37.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类38."关于以下代码,说法正确的是?class Example {public static void main(String[] args) throws IOException {System.out.println(""Before Try"");try {} catch (Throwable e) {System.out.println(""Inside Catch"");}System.out.println(""At the End"");}}"答案:BA.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C."输出Before TryAt the End"D."输出Inside CatchAt the End"39."当fragile()方法抛出一个IllegalArgumentException异常时,下列代码的运行结果是什么?public static void main(String[] args) throws IOException {try {fragile();} catch (NullPointerException e) {System.out.println(""NullPointerException thrown"");} catch (Exception e) {System.out.println(""Exception thrown"");} finally {System.out.println(""Done with exceptions"");}System.out.println(""myMethod is done"");}}"答案:A.输出NullPointerException thrownB.输出Exception thrownC.输出Done with ExceptionD.输出myMethod is done40."下列代码的执行结果是?class Example {public static void main(String[] args) throws IOException {int i = 1, j = 1;try {i++;j--;if (i == j) {j++;}} catch (ArithmeticException e) {System.out.println(0);} catch (ArrayIndexOutOfBoundsException e) {System.out.println(1);} catch (Exception e) {System.out.println(2);} finally {System.out.println(3);}System.out.println(4);}}"答案:CDA.输出1B.输出2C.输出3D.输出441.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String42.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前43."请问以下代码的直接执行结果是?class Example{public static void main(String[] args) {try {System.out.println(args[0]);System.out.println(""I'm nomal"");if (true)return;} catch (Exception ex) {System.out.println(""I'm exception"");if (true)return;} finally {System.out.println(""I'm finally."");}System.out.println(""Out of try."");}}"答案:AA."I'm exceptionI'm finally."B.代码不能编译通过,因为最后一条语句位于return后,不可到达C.代码编译通过,但运行时输出异常信息D."I'm nomalI'm finally."44."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息45.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException46."现有:public class Example {public static void main(String[] args) {TreeSet<String> s = new TreeSet<String>();s.add(""one"");s.add(""two"");// 插入代码处for (String s2 : sorted) {System.out.print(s2 + "" "");}}}和四个代码片段:s1:SortedSet sorted = s.tailSet(s.first());s2:SortedSet<String> sorted = s.tailSet(s.first());s3:SortedSet sorted = (SortedSet)s.tailSet(s.first());s4:SortedSet sorted = (SortSet<String>)s.tailSet(s.first()); 分别插入到插入代码处,哪项可以编译?"答案:A.S2B.S2和S3C.S2和S4D.S2、S3和S447."对以下两个代码片段说法正确的是?代码片段1:int a = 3;int b = 0;int c = a / b;代码片段2:float a = 3.0f;float b = 0.0f;float c = a / b;"答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常48."以下代码执行的结果是:public class Example {public static void main(String[] args) {int[] x = { 1, 2, 3 };x[1] = (x[1] > 1) ? x[2] : 0;System.out.println(x[1]);}}"A.输出1B.输出2C.输出3D.输出449.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以50.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;51.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];52.以下那种初始化数组的方式是错误的?答案:CA.String[] names = {"zhang","wang","li"};B."String names[] = new String[3];names[2] = ""li"";names[0] = ""zhang"";names[1] = ""wang"";"C.String[3] names = {"zhang","wang","li"};D.以上写法都正确53.以下哪些是声明一个字符串数组的正确形式?答案:ABDA.String[] s;B.String []s;D.String s[]54.以下哪些语句正确?答案:ADA.double snow[] = new double[31];B.double snow[31] = new array[31];C.double snow[31] = new array;D.double[] snow = new double[31];55.以下哪些是初始化数组的正确形式?答案:ABDA.char c[] = {'a','b'};B.int []x[] = {{1,2,3},{1,2,3}};C.int x[3] = {1,2,3};D.int []x = {0,0,0};56.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len57.假设存在int型数组a,哪项是正确的增强for循环迭代该数组?答案:CA.for(int[] a){}B.for(int a){}C.for(int x:a){}D.for(int i>0;i<a.length;i++){}58."下列代码执行后的输出是哪项?public class Example {public static void main(String[] args) {List<String> al = new ArrayList<String>();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]59."下列代码的执行结果是什么?public class Example {public static void main(String[] args) {int index = 1;int[] foo = new int[3];int bar = foo[index];int baz = bar + index;System.out.println(baz);}}"答案:BA.打印输出0B.打印输出1C.打印输出2D.运行期间有异常抛出60."public class TestReplace {public static void stringReplace(String text){text=text.replace('j', 'i');}public static void bufferReplace(StringBuffer text){ text=text.append(""C"");}public static void main(String[] args){String textString=new String(""java""); StringBuffer bufferString=new StringBuffer(""java"");stringReplace(textString);bufferReplace(bufferString);System.out.println(textString+bufferString);}}运行结果是?"答案:AA.javajavaCB.javaCjavaCC.javajavaD.javajavaCjava61.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入62."以下程序执行结果是?public class Example {public static void main(String[] args) throws IOException {String s = ""x,yy,123"";Scanner sc = new Scanner(s);while (sc.hasNext()) {System.out.println(sc.next() + "" "");}}}"答案:A.x yyB.x,yy,123C.x yy 123D.x,yy63.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程64."以下代码的执行结果是?public class Example implements Runnable {public static void main(String args[]) {Example ex = new Example();Thread t = new Thread(ex);t.start();}void run() {System.out.print(""pong"");}}"答案:A.输出pongB.运行时输出异常信息C.运行后无任何输出D.编译失败65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:public void run() {System.out.print(""go"");}执行:t.start();t.start();t.run();后结果是什么?"答案:A.go goB.go go goC.go之后跟着一个异常D.go go之后跟着一个异常66."下列代码的执行结果是?public class Example{public static void main(String args[]) {Thread t = new Thread() {public void run() {pong();}};t.run();System.out.print(""ping"");}static void pong() {System.out.print(""pong"");}}"答案:A.pingpongB.pongpingC.pingpong和pongping都有可能D.都不输出67.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对68.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。