精编新版JAVASE综合模拟考试188题(含参考答案)
精选新版JAVASE综合完整题库188题(含标准答案)

2020年JAVASE综合考试试题库188题[含答案]一、选择题1."下列代码执行后的输出是哪项?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]2.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.033."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息4."以下代码的运行结果是什么?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.05."给出以下代码,请问在程序的第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]));6."以下代码执行结果是?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不是有效的参数7.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快8.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set9.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化10.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map11.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型12.创建一个只能存放String的泛型ArrayList的语句是哪项?答案:BA.ArrayList<int> al = new ArrayList<int>();B.ArrayList<String> al = new ArrayList<String>();C.ArrayList al = new ArrayList<String>();D.ArrayList<String> al = new List<String>();13.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()14."现有: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())15."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo16."现有: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和S417.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对18."现有如下类型:a - java.util.Hashtableb - java.util.Listc - java.util.ArrayListd - java.util.SortedSet和定义:1-使用本接口,允许用户控制集合中每个元素的插入位置2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合3-本具体类型允许空元素及基于索引的访问4-本集合是同步的哪一组匹配是对的?"答案:A.2描述d,3描述bB.1描述b,3描述cC.3描述a,4描述bD.4描述a,2描述c19."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();20.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor21."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出22."现有如下代码:public class Example {public static void main(String[] args) {try {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) {23.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()24."关于以下代码,说法正确的是?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"25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String27."请问以下代码的直接执行结果是?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."28."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息29.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException30.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws31."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {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.编译失败32."现有如下代码:public class Example {public static void main(String[] args) {// anew Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d33."下面代码的执行结果是?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.编译失败34.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()35."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性36.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double37."给出以下代码: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 Exception38."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try39."以下代码中,如果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.以上都不对40."以下代码执行结果是什么?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 IOException {foo(0);foo(1);System.out.println(output);}}"答案:A.无内容输出B.代码编译失败C.输出13423D.输出1432341."以下代码执行结果是?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.代码编译成功42."关于以下代码正确的说法是: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行编译错误43."现有如下代码: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 catch44.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常45.下列关于Math类说法错误的是ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值46."现有:String s = ""write a line to a file"";w.print(s + ""\n"");哪一个是对的?"答案:A.w既可以是PrintWriter类型,也可以是BufferedWriter类型B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型47.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行48.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();49."下列代码在JDK1.5以上版本执行的结果是?public class Example {public static void main(String[] args) {Integer i = 10;Integer j = 10;System.out.println(i == j);i = 210;j = 210;System.out.println(i == j); (超过-128~127为false)}答案:BA.抛出异常B.输出true falseC.输出true trueD.输出false false50.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型51.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;52.下面哪条语句不正确?答案:CA.int[] a={1,2,3};B.int a[]=new int[4];C.int[] a=new int[];D.int[] a=new int[]{2,3,4};53.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];54.以下那种初始化数组的方式是错误的?答案: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.以上写法都正确55.以下哪些是声明一个字符串数组的正确形式?答案:ABDA.String[] s;B.String []s;C.Sting [s]D.String s[]56.以下哪些语句正确?答案: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];57.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len58."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = 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){59."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null60."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."下列代码的执行结果是什么?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.运行期间有异常抛出62."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null63.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入64."以下程序执行结果是?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,yy65.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程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。
新版精编JAVASE综合完整题库188题(含答案)

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."以下代码的输出结果是什么?选择所有的正确答案。
最新JAVASE综合考核题库完整版188题(含标准答案)

2020年JAVASE综合考试试题库188题[含答案]一、选择题1.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化2."下列代码的执行结果是?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 Exception3."以下代码的输出结果是什么?选择所有的正确答案。
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.74.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常5.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值6.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double7.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()8."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息9."以下代码的运行结果是什么?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.010."给出以下代码,为了结果输出-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()11."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();12.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set13."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try14.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set15.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序16.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()17."现有: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())18."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo19."现有: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和S420.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对21."以下代码执行结果是?public class Example {public static void main(String[] args) {TreeMap<String, String> map = new TreeMap<String, String>(); map.put(""one"", ""1"");map.put(""two"", ""2"");map.put(""three"", ""3"");displayMap(map);}static void displayMap(TreeMap map) {Collection<String> c = map.entrySet();Iterator<String> i = c.iterator();while (i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}"答案:A.onetwothreeB.123C.one=1three=3two=2D.onethreetwo22.请问以下哪个程序代码体现了对象之间的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;}"23.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快24.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26."现有以下代码:interface W {}class Z implements W {}class X extends Z {}class Y 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;"27.Java语言中异常的分类是哪项?答案:CA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常28."现有代码: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.编译失败29."对以下两个代码片段说法正确的是?代码片段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抛出异常30."下列代码执行后的结果是?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.输出NaN31."现有如下代码: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.编译失败32.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类33."关于以下代码,说法正确的是?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"34."关于以下代码正确的说法是: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行编译错误35."下列代码的执行结果是?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.输出436."以下代码中,如果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.以上都不对37."请问以下代码的直接执行结果是?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."38.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException39.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws40."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {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.编译失败41."下面代码的执行结果是?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.编译失败42.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行43."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性44."关于以下代码,说法正确的是?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"45."给出以下代码: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 Exception46."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出47."当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 done48."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null49.Java语言中有多少个包装器类型?答案:BA.7B.8C.950."下列代码在JDK1.5以上版本执行的结果是?public class Example {public static void main(String[] args) {Integer i = 10;Integer j = 10;System.out.println(i == j);i = 210;j = 210;System.out.println(i == j); (超过-128~127为false)}}"答案:BA.抛出异常B.输出true falseC.输出true trueD.输出false false51.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型52.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;53.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];54.以下那种初始化数组的方式是错误的?A.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.以上写法都正确55.数组索引从几开始?答案:AA.0B.1C.-1D.随便56.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len57."以下给出代码运行后的结果是?public class Example {public static void main(String[] args) {int[] refToArray = { 10, 11 };int var = 1;refToArray[var - 1] = var = 2;System.out.println(refToArray[0] + "" "" + refToArray[1]); }}"答案:CA.编译失败B.编译通过,但运行时提示异常C.2 11D.10 258."现有如下类型:a - java.util.Hashtableb - java.util.Listc - java.util.ArrayListd - java.util.SortedSet和定义:1-使用本接口,允许用户控制集合中每个元素的插入位置2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合3-本具体类型允许空元素及基于索引的访问4-本集合是同步的哪一组匹配是对的?"答案:A.2描述d,3描述bB.1描述b,3描述cC.3描述a,4描述bD.4描述a,2描述c59."下列代码的执行结果是什么?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 TestEquals {/*** @param args*/public static void main(String[] args) {String a=""a"";String b=""b"";String c=""a""+""b"";String d=a+b;System.out.println(a==""a"");System.out.println(c==""ab"");System.out.println(d==c);System.out.println(new String(""a"")+b==c);}}运行结果是?"答案:DA."truefalsefalsefalse"B."truetruefalsefalse"C."truetruetruefalse"D."falsefalsefalsefalse"61."以下代码执行的结果是: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]);}}"答案:CA.输出1B.输出2C.输出3D.输出462."以下程序执行结果是?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();后结果是什么?"答案: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。
精选新版JAVASE综合模拟考试188题(含答案)

2020年JAVASE综合考试试题库188题[含答案]一、选择题1.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map2.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()3.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double4.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()5.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.036."以下代码的运行结果是什么?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.07."给出以下代码,为了结果输出-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()8."给出以下代码,请问在程序的第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]));9.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快10.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set11."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出12.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set13."关于以下代码正确的说法是: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行编译错误14.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序15.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()16.创建一个只能存放String的泛型ArrayList的语句是哪项?答案:BA.ArrayList<int> al = new ArrayList<int>();B.ArrayList<String> al = new ArrayList<String>();C.ArrayList al = new ArrayList<String>();D.ArrayList<String> al = new List<String>();17."现有: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())18."现有: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和S419.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对20."以下代码执行结果是?public class Example {public static void main(String[] args) {TreeMap<String, String> map = new TreeMap<String, String>(); map.put(""one"", ""1"");map.put(""two"", ""2"");map.put(""three"", ""3"");displayMap(map);}static void displayMap(TreeMap map) {Collection<String> c = map.entrySet();Iterator<String> i = c.iterator();while (i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}"答案:A.onetwothreeB.123C.one=1three=3two=2D.onethreetwo21."现有如下类型:a - java.util.Hashtableb - java.util.Listc - java.util.ArrayListd - java.util.SortedSet和定义:1-使用本接口,允许用户控制集合中每个元素的插入位置2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合3-本具体类型允许空元素及基于索引的访问4-本集合是同步的哪一组匹配是对的?"答案:A.2描述d,3描述bB.1描述b,3描述cC.3描述a,4描述bD.4描述a,2描述c22."下列代码执行后的结果是?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.输出NaN23.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化24.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26.下列属于非受检异常(运行时异常)的是哪项?答案:AA.IOExceptionB.NullPointerExceptionC.OutOfMemoryErrorD.27.请问以下哪个程序代码体现了对象之间的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;}"28.Java语言中异常的分类是哪项?答案:CA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常29."现有代码: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.编译失败30."对以下两个代码片段说法正确的是?代码片段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抛出异常31.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类32."关于以下代码,说法正确的是?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"33.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有34.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常35."下列代码的执行结果是?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.输出436."现有如下代码: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 catch37."请问以下代码的直接执行结果是?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."38.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException39.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws40."现有如下代码:public class Example {public static void main(String[] args) {// anew Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d41."下面代码的执行结果是?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.编译失败42.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行43."以下代码中,如果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.以上都不对44."以下代码执行结果是什么?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 IOException {foo(0);foo(1);System.out.println(output);}}"答案:A.无内容输出B.代码编译失败C.输出13423D.输出1432345."以下代码执行结果是?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.代码编译成功46.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法47."当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 done48.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();49."下列代码在JDK1.5以上版本执行的结果是?public class Example {public static void main(String[] args) {Integer i = 10;Integer j = 10;System.out.println(i == j);i = 210;j = 210;System.out.println(i == j); (超过-128~127为false)}}"答案:BA.抛出异常B.输出true falseC.输出true trueD.输出false false50.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型51.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以52.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;53.下面哪条语句不正确?答案:CA.int[] a={1,2,3};B.int a[]=new int[4];C.int[] a=new int[];D.int[] a=new int[]{2,3,4};54.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];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.数组索引从几开始?答案:AA.0B.1C.-1D.随便57.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len58."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?" 答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();59."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null60."public class TestEquals {/*** @param args*/public static void main(String[] args) { String a=""a"";String b=""b"";String c=""a""+""b"";String d=a+b;System.out.println(a==""a"");System.out.println(c==""ab"");System.out.println(d==c);System.out.println(new String(""a"")+b==c); }}运行结果是?"答案:DA."truefalsefalsefalse"B."truetruefalsefalse"C."truetruetruefalse"D."falsefalsefalsefalse"61."下列代码的执行结果是什么?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.运行期间有异常抛出62."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null63."以下代码执行的结果是: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]);}}"答案:CA.输出1B.输出2C.输出3D.输出464.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入65."以下程序执行结果是?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,yy66.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()67."以下代码的执行结果是?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.编译失败68.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对69.Java UDP编程主要用到的两个类型是答案:A.UDPSocketB.DatagramSocketC.UDPPacketD.DatagramPacket70.假设存在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++){}71.为了能够访问对封装的属性的访问和修改,方法往往用哪个修饰符修饰?答案:AA.publicB.protectedC.privateD.都可以72."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = 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){73.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型74.以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.PrintStreamC.ReaderD.FileInputStream75.以下哪些描述是正确的?答案:A.InputStream和OutputStream类是基于字节流的B.ObjectInputStream类和ObjectOutputStream类不支持序列化的对象C.Reader和Writer是基于字符流的D.Reader类和Writer类是支持对象序列化的首选76.以下哪些描述是正确的?答案:A.Writer类可以使用不同的字符编码向输出流写入字符B.Writer类可以向输出流写入Unicode字符C.Writer类提供向输出流写入任意Java基本数据类型的方法D.Writer类提供向输出流写入引用数据类型的方法77.方法可以使用哪个访问权限修饰符?答案:DA.publicB.protectedC.privateD.都可以78.属性可以使用哪个访问权限修饰符?答案:CA.publicB.protectedC.privateD.都可以79.构造方法可以使用哪个访问权限修饰符?答案:AA.publicB.protectedC.privateD.都可以80.只允许子类及同包类访问某方法,使用哪个修饰符?答案:BA.publicB.protectedC.privateD.都可以81."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.javajavaCjava82.为了实现对属性的封装,属性使用哪个访问权限修饰符?答案:CA.publicB.protectedC.privateD.default83."以下程序运行的结果是:public class Example {public static void main(String[] args) {System.out.println(""String"".replace('g', 'G') == ""String"".replace('g','G')); System.out.println(""String"".replace('t', 't') == ""String"".replace('t','t')); }}"答案:CA.输出true trueB.输出true falseC.输出false falseD.输出false true84.以下哪些是关于完全封装的正确描述?答案:CA.所有的变量都是私有的B.所有的方法都是私有的C.只有通过提供的方法才能访问类属性D.通过方法和变量名均可访问属性85."执行下列语句后,变量i的值是:byte i = 127; byte(-2^7 ~ 2^7-1)i += 1; (当溢出时回到最小)"答案:DA.128B.0D.-12886."执行下列语句后,变量i的值是:byte i = 127;i = i+ 2;"答案:-127A.0B.编译不能通过C.运行时抛出异常D.-12887.char类型的取值范围是?答案:A.0-2^16B.0-2^16-1C.-2^15-2^15D.0-2^15-188.下面哪个赋值语句是合法的?答案:CA.float a = 2.0B.double b = 2.0C.int c = 2D.long d = 289.下面哪个类型是引用类型?答案:AA.EmployeeB.intC.charD.double90.下面哪个不是引用类型?答案:DA.StringB.DoubleC.FloatD.float91.下面哪个说法正确?答案:AA.基本数据类型都可以直接使用=赋值B.引用类型绝对不能直接用=赋值,都需要使用new关键字C.String不是引用类型D.char是引用类型92."Student s1=new Student(""John"");Student s2=new Student(""Alice"");s1=s2;System.out.println(s1.getName());输出结果为?"答案:DA.JohnB.nullC.AliceD.不能确定93.以下有关ng.Exception异常类的正确描述有?答案:BA.该类是一个公共类B.该类是Throwable类的子类C.该类实现了Throwable接口D.该类可以序列化94.如果类中的成员变量只可以被同一包访问,则使用如下哪个约束符?答案:CA. privateB.publicC.protectedD.no modifier95.关于Java源代码文件,下列说法错误的是?答案:DA.一个源文件最多只能包含一个顶层的public类定义B.一个源文件可以不包含任何代码定义。
最新JAVASE综合模拟题库188题(含答案)

}
}
"
答案:B
A.输出Ceil d1=-0.0 Floor d1=-1.0
B.输出Ceil d1=0.0 Floor d1=-1.0
C.输出Ceil d1=-0.0 Floor d1=-0.0
D.输出Ceil d1=0.0 Floor d1=0.0
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());
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1."以下代码的执行结果是?
public class Example {
public static void main(String[] args) {
TreeSet<String> t = new TreeSet<String>();
C.ArrayList al = new ArrayList<String>();
D.ArrayList<String> al = new List<String>();
13.Java语言中异常的分类是哪项?
精选最新版JAVASE综合测试题库188题(含答案)

2020年JAVASE综合考试试题库188题[含答案]一、选择题1."现有如下代码: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 catch2.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前3."请问以下代码的直接执行结果是?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."4.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws5."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {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.编译失败6."现有如下代码:public class Example {public static void main(String[] args) {// anew Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d7."下面代码的执行结果是?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.编译失败8.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行9."关于以下代码,说法正确的是?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"10."给出以下代码: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 Exception11.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set12."以下代码执行结果是?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.代码编译成功13.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有14.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常15.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()16.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.0317."以下代码的输出结果是什么?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.运行时输出异常信息18."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息19."给出以下代码,为了结果输出-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()20."给出以下代码,请问在程序的第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]));21."以下代码执行结果是?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不是有效的参数22.关于集合中对象的equals()和hashCode()规定说法错误的是?答案:CA.如果两个对象相同,那么他们的hashCode值需要一致B.如果两个对象的hashCode值一致,他们的equals方法不一定返回trueC.equals方法默认和==判定一致D.Java中hashCode就是对象的内存地址23."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try24."下列代码执行后的结果是?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 true25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26."以下代码执行结果是?class RectObject {public int x;public int y;public RectObject(int x, int y) {this.x = x;this.y = y;}@Overridepublic int hashCode() {// TODO Auto-generated method stubreturn (int)System.nanoTime();}@Overridepublic boolean equals(Object obj) {return false;}}public class Example {public static void main(String[] args) {HashSet<RectObject> set = new HashSet<RectObject>();RectObject r1 = new RectObject(3, 3);RectObject r2 = new RectObject(5, 5);RectObject r3 = new RectObject(3, 3);set.add(r1);set.add(r2);set.add(r3);set.add(r1);System.out.println(""size:"" + set.size());}}"答案:A.size:1B.size:2C.size:3D.size:427.关于接口的说法,正确的是()答案:CA.接口中的方法只能在接口的实现类中实现B.接口中可定义变量成员C.接口中不能定义常量D.以上都不对28.请选择所有的正确答案。
精选新版JAVASE综合模拟考试题库188题(含答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."下列代码执行后的输出是哪项?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]2.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double3.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()4.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.035."以下代码的输出结果是什么?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.运行时输出异常信息6."给出以下代码,为了结果输出-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()7."以下代码执行结果是?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不是有效的参数8.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快9.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set10.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化11.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型12.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()13."现有如下代码: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 catch14."现有: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())15."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo16."现有: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和S417.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对18."以下代码执行结果是?public class Example {public static void main(String[] args) {TreeMap<String, String> map = new TreeMap<String, String>(); map.put(""one"", ""1"");map.put(""two"", ""2"");map.put(""three"", ""3"");displayMap(map);}static void displayMap(TreeMap map) {Collection<String> c = map.entrySet();Iterator<String> i = c.iterator();while (i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}"答案:A.onetwothreeB.123C.one=1three=3two=2D.onethreetwo19."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?" 答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();20.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor21.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法22.所有异常的父类是哪项?答案:AA.ThrowableB.ErrorC.RuntimeExceptionD.Exception23.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序24.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前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.println(x % y == x % y);} catch (Exception e) {System.out.println(""Exception"");}}}"答案:DA.编译失败B.运行时抛出异常C.打印输出trueD.打印输出false27.下列属于非受检异常(运行时异常)的是哪项?答案:AA.IOExceptionB.NullPointerExceptionC.OutOfMemoryErrorD.28.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,29.请问以下哪个程序代码体现了对象之间的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;}"30."给出以下代码,改程序的执行结果是?interface 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.打印输出031."现有以下代码:interface W {}class Z implements W {}class X extends Z {}class Y 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;"32."现有代码: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.编译失败33."对以下两个代码片段说法正确的是?代码片段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抛出异常34.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()35.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String36.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值37."现有代码如下: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 middle38."下面代码的执行结果是?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.编译失败39.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行40."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性41."关于以下代码,说法正确的是?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"42."给出以下代码: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 Exception43."给出以下代码,执行结果是?class Example {public static void main(String[] args) throws IOException {aMethod();}static void aMethod(){try {System.out.println(""Try"");return;} catch (Exception e) {System.out.println(""Catch"");}finally{System.out.println(""Finally"");}}}"答案:A.代码编译成功,但运行期间抛出异常B.代码便以失败,因为return语句错误C.输出Try和FinallyD.输出Try44."以下代码执行结果是什么?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 IOException { foo(0);foo(1);System.out.println(output);}}"答案:A.无内容输出B.代码编译失败C.输出13423D.输出1432345."关于以下代码正确的说法是: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行编译错误46."现有:String s = ""write a line to a file"";w.print(s + ""\n"");哪一个是对的?"答案:A.w既可以是PrintWriter类型,也可以是BufferedWriter类型B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型47.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有48.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();49.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型50.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以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;C.Sting [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.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; 答案:DCA.s[10] 为 ""B.s[9] 为 nullC.s[0] 为未定义D.s.length 为1057.数组索引从几开始?答案:AA.0B.1C.-1D.随便58."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = 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){59."以下给出代码运行后的结果是?public class Example {public static void main(String[] args) {int[] refToArray = { 10, 11 };int var = 1;refToArray[var - 1] = var = 2;System.out.println(refToArray[0] + "" "" + refToArray[1]); }}"答案:CA.编译失败B.编译通过,但运行时提示异常C.2 11D.10 260."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."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null62."以下代码执行的结果是: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]);}}"答案:CA.输出1B.输出2C.输出3D.输出463."以下程序执行结果是?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,yy64.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程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。
精编新版JAVASE综合模拟题库188题(含标准答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo2.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值3.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double4."以下代码的输出结果是什么?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.运行时输出异常信息5."给出以下代码,为了结果输出-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()6."给出以下代码,请问在程序的第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]));7."以下代码执行结果是?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不是有效的参数8.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快9.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map10.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序11.以下哪些是FileOutputSteram类的正确构造形式?答案:A.FileOutputStream(FileDescriptor fd)B.FileOutputStream(String n,boolean a)C.FileOutputStream(boolean a)D.FileOutputStream(File f)12."下列代码执行后的输出是哪项?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]13."下列代码的执行结果是?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 Exception14."现有: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和S415.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对16."现有:public class Example {public static void main(String[] args) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();17.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor18."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出19.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法20."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = 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){21.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型22."现有以下代码:interface W {}class Z implements W {}class X extends Z {}class Y 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;"23.创建一个只能存放String的泛型ArrayList的语句是哪项?答案:BA.ArrayList<int> al = new ArrayList<int>();B.ArrayList<String> al = new ArrayList<String>();C.ArrayList al = new ArrayList<String>();D.ArrayList<String> al = new List<String>();24.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26."下列代码执行后的结果是?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.输出NaN27.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类28.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有29."现有如下代码:public class Example {public static void main(String[] args) {try {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) {30."下列代码的执行结果是?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.输出431."请问以下代码的直接执行结果是?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."32."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息33.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException34.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常35."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {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.编译失败36."以下代码的输出结果是什么?选择所有的正确答案。
精编JAVASE综合模拟考试188题(含答案)
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码的执行结果是?public class Example {public static void main(String[] args) {TreeSet<String> t = new TreeSet<String>();if (t.add(""one""))if (t.add(""two""))if (t.add(""three""))t.add(""four"");for (String s : t) {System.out.print(s);}}}"答案:DA.oneB.onethreetwoC.onetwothreefourD.fouronethreetwo2.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()3.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()4."以下代码的输出结果是什么?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.运行时输出异常信息5."以下代码的运行结果是什么?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.06."给出以下代码,请问在程序的第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]));7.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快8.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set9.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化10.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set11."现有:String s = ""write a line to a file"";w.print(s + ""\n"");哪一个是对的?"答案:A.w既可以是PrintWriter类型,也可以是BufferedWriter类型B.w既不可以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型12.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序13."以下代码执行结果是?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.代码编译成功14."现有: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和S415.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对16."以下代码执行结果是?public class Example {public static void main(String[] args) {TreeMap<String, String> map = new TreeMap<String, String>(); map.put(""one"", ""1"");map.put(""two"", ""2"");map.put(""three"", ""3"");displayMap(map);}static void displayMap(TreeMap map) {Collection<String> c = map.entrySet();Iterator<String> i = c.iterator();while (i.hasNext()) {Object o = i.next();System.out.print(o.toString());}}}"答案:A.onetwothreeB.123C.one=1three=3two=2D.onethreetwo17."现有如下类型:a - java.util.Hashtableb - java.util.Listc - java.util.ArrayListd - java.util.SortedSet和定义:1-使用本接口,允许用户控制集合中每个元素的插入位置2-使用本集合,确保用户可以按照递增或元素的自然顺序遍历集合3-本具体类型允许空元素及基于索引的访问4-本集合是同步的哪一组匹配是对的?"答案:A.2描述d,3描述bB.1描述b,3描述cC.3描述a,4描述bD.4描述a,2描述c18.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor19."以下代码的执行结果是?public class Example {public static void main(String[] args) {File f = new File(""c:\\large.txt"");}}"答案:rge.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确rge.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出20.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法21."现有:f是一个File类实例的合法引用fr是一个FileReader类实例的合法引用br是一个BufferedReader类实例的合法引用如下代码:String line = 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){22."现有代码: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.编译失败23.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map24."现有代码如下: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 middle25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26."现有如下代码: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.编译失败27.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类28."关于以下代码,说法正确的是?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"29."当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 done30."现有如下代码:public class Example {public static void main(String[] args) {try {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) {31.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String32.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前33."请问以下代码的直接执行结果是?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."34.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值35.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException36."以下代码的输出结果是什么?选择所有的正确答案。
最新版精编2020年JAVASE综合模拟考试188题(含答案)
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1.表示键值对概念的接口是哪项?
答案:D
A.Set
B.List
C.Collection
D.Map
2.Java语言中异常的分类是哪项?
答案:
A.运行时异常和异常
B.受检异常和非受检异常
C.错误和异常
D.错误和运行时异常
3.下列关于Math类说法错误的是
答案:
ng.Math类是final类,因此不能被其他类继承
ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象
ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用
D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
4.以下哪个方法是Math类中定义的?
答案:
A.absolute()
B.log()
C.cosine()
D.sine()
5.定义在Math类上的round(double d)方法的返回值类型是什么?
答案:
A.char
B.int
C.long
D.double。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C.FileOutputStream(boolean a)
D.FileOutputStream(File f)
12.以下哪些集合接口支持重复元素存在?
答案:B
A.Collection
B.List
C.Map
D.Set
13."以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?
A.不允许重复元素,元素有顺序
ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用
D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
5.定义在Math类上的round(double d)方法的返回值类型是什么?
答案:
A.char
B.int
System.out.println(""Message2"");
}finally{
System.out.println(""Message3"");
}
}
}"
答案:
A.打印输出Message1
B.打印输出Message2
C.打印输出Message3
D.以上都不对
14.List接口的特点是哪项?
答案:C
}
public static void doRisyThing() throws Exception{
//this code returns unless it throws an Exception
}
}
该代码可能的执行结果有哪些?"
答案:
A.before catch
B.before after done
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"");
D.i[1] = ((int)Math.floor(x[a]));
10.下列哪些项是泛型的优点?
答案:A
A.不用向下强制类型转换
B.代码容易编写
C.类型安全
D.运行速度快
11.以下哪些是FileOutputSteram类的正确构造形式?
答案:
A.FileOutputStream(FileDescriptor fd)
try {
System.out.println(""before"");
doRisyThing();
System.out.println(""after"");
} catch (Exception e) {
System.out.println(""catch"");
}
System.out.println(""done"");
8."以下代码的运行结果是什么?
public class Example {
public static void main(String[] args) {
System.out.println(Math.min(0.0, -0.0));
}
}"
答案:C
A.代码编译失败
B.输出0.0
C.输出-0.0
D.代码编译成功,但运行时输出异常信息
C.before catch done
D.before after catch
3."以下代码的输出结果是什么?选择所有的正确答案。
class Example {
public static void main(String[] args) throws IOException {
for (int i = 0; i < 10; i++) {
5. for (int a = 0; a < x.length; a++) {
6.
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]));
C.long
D.double
6.以下哪个方法用于计算平方根?
答案:B
A.squareRoot()
B.sqrt()
C.root()
D.sqr()
7.调用Math.random()方法最有可能输出以下哪些结果?
答案:D
A.-0.12和0.56E3
B.0.12和1.1E1
C.-23.45和0.0
D.0.356和0.03
2020年JAVASE综合考试试题库188题[含答案]
一、选择题
1.表示键值对概念的接口是哪项?
答案:D
A.Set
B.List
C.Collection
D.Map
2."现有如下代码:
public class Example {
public static void main(String[] args) {
9."给出以下代码,请问在程序的第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];
} finally {
++i;
}
} catch (Exception outeally {
--i;
}
}
}
}"
答案:
A.4
B.5
C.6
D.7
4.下列关于Math类说法错误的是
答案:
ng.Math类是final类,因此不能被其他类继承
ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象
class Example {
public static void main(String[] args) throws IOException {
try {
test();
System.out.println(""Message1"");
} catch (ArrayIndexOutOfBoundsException e) {