1、精选新版JAVASE综合模拟考试题库188题含参考答案2020年JAVASE综合考试试题库188题含答案一、选择题1以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection();D.以上都不对2调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.033以下代码的运行结果是什么?public
2、 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
3、= + 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 int3;5. f
4、or (int a = 0; a x.length; a+) 6.7. System.out.println(ia);8. 9. 10.答案:CA.i1 = (int)Math.min(xa);B.i1 = (int)Math.max(xa);C.i1 = (int)Math.ceil(xa);D.i1 = (int)Math.floor(xa);6下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快7以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set8表示键值对概念的接口是哪项?答案:D
5、A.SetB.ListC.CollectionD.Map9List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序10欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()11以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.
6、PrintStreamC.ReaderD.FileInputStream12以下代码的执行结果是?public class Example public static void main(String args) TreeSet t = new TreeSet(); 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.fouronethreetwo13以下哪个方法是M
7、ath类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()14现有如下类型: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描述c15现有:publi
8、c 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();16以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor17以下代码的执行结果是?public
9、class Example public static void main(String args) File f = new File(c:large.txt); 答案:A.large.txt文件在本地硬盘上被创建B.在Unix系统上运行失败,因为路径分割符不正确C.large.txt文件在本地硬盘上没有被创建D.如果large.txt文件已经存在,则一个异常被抛出18以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘
10、文件的方法19现有: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)20现有int x =
11、 reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型21现有:String s = write a line to a file;w.print(s + n);哪一个是对的?答案:A.w既可以是PrintWriter类型,也可以是BufferedWriter类型B.w既不可
12、以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型22下列代码执行后的结果是?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(Except
13、ion); 答案:DA.编译失败B.输出ExceptionC.输出InfinityD.输出NaN23创建一个只能存放String的泛型ArrayList的语句是哪项?答案:BA.ArrayList al = new ArrayList();B.ArrayList al = new ArrayList();C.ArrayList al = new ArrayList();D.ArrayList al = new List();24如下代码执行后的输出结果是?public class Example public static void main(String args) try throw ne
14、w 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.编译失败25以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredField
15、s()D.getImports()26关于异常处理,说法错误的是?答案:CA.trycatchfinally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类27关于以下代码,说法正确的是?class Example public static void main(String args) throws
16、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 EndD.输出Inside CatchAt the End28关于trycatchfinally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有cat
17、chD.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
18、 (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.
19、println(2); finally System.out.println(3); System.out.println(4); 答案:CDA.输出1B.输出2C.输出3D.输出431以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String32请问以下代码的直接执行结果是?class Example public static void main(String args) try System.out.println(args0); System.out.println(Im nomal); if (true) retu
20、rn; catch (Exception ex) System.out.println(Im exception); if (true) return; finally System.out.println(Im finally.); System.out.println(Out of try.); 答案:AA.Im exceptionIm finally.B.代码不能编译通过,因为最后一条语句位于return后,不可到达C.代码编译通过,但运行时输出异常信息D.Im nomalIm finally.33下列代码的运行结果是?class Example public static void m
21、ain(String args) throws IOException try return; finally System.out.println(Finally); 答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息34以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()35在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throw B.catchC.finallyD.throws36定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.i
22、ntC.longD.double37现有如下代码:public class Example public static void main(String args) / a new Example().topGo(); void topGo() / b middleGo(); void middleGo() / c go(); System.out.println(late middle); void go() / d throw new Exception(); 为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?答案:BA.dB.c和dC.b、c和dD.a、b、
23、c和d38请问以下哪些关于trycatchfinally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行39关于以下代码,说法正确的是?class Example public static void main(String args) throws IOException if (args0 = hello) throw n
24、ew IOException(); 答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性40关于以下代码,说法正确的是?class Example public static void main(String args) throws IOException System.out.println(Before Try); try catch (java.io.IOException e) System.out.println
25、(Inside Catch); System.out.println(At the End); 答案:A.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C.输出Before TryAt the EndD.输出Inside CatchAt the End41以下代码中,如果test()方法抛出一个NullPointException异常时,打印输出什么内容?class Example public static void main(String args) throws IOException try test(); System.out.println(M
26、essage1); catch (ArrayIndexOutOfBoundsException e) System.out.println(Message2); finally System.out.println(Message3); 答案:A.打印输出Message1B.打印输出Message2C.打印输出Message3D.以上都不对42以下代码执行结果是什么?class Example public static String output = ; public static void foo(int i) try if (i = 1) throw new Exception(); o
27、utput += 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.输出1432343现有如下代码: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 doRi
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1