精选新版2020年JAVASE综合完整题库188题(含标准答案)
精选新版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.一个源文件可以不包含任何代码定义。
精选最新2020年JAVASE综合模拟考试题库188题(含参考答案)

2020年JAVASE综合考试试题库188题[含答案]一、选择题1.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快2."现有如下代码: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 catch3."下列代码的执行结果是?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 Exception4."以下代码的输出结果是什么?选择所有的正确答案。
精选新版JAVASE综合考核题库188题(含答案)

2020年JAVASE综合考试试题库188题[含答案]一、选择题1.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()2."下面代码的执行结果是?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.编译失败3."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性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."给出以下代码,执行结果是?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.输出Try6."以下代码中,如果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.以上都不对7."以下代码执行结果是什么?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.输出143238."以下代码的输出结果是什么?选择所有的正确答案。
精选最新版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"");。
精选2020年JAVASE综合模拟考试188题(含参考答案)

a.method2();
}
}"
答案:
A.代码编译失败
B.输出Caught Runtime Exception
C.输出Caught Exception
D.输出Caught Runtime Exception和Caught Exception
14.List接口的特点是哪项?
System.out.println(""Floor d1="" + Math.floor(d1));
}
}
"
答案: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
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]
}
}"
答案: A
A.floor()
B.ceil()
C.round()
D.abs()
9."以下代码执行结果是?
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2020年JAVASE综合考试试题库188题[含答案] 一、选择题 1."现有: list是一个合法的集合引用 getCollection()返回一个合法集合的引用,以下语句哪些是合法的?" 答案:C A.for(Object o : list) B.for(Object o : getCollection()) C.for(Object o : list.iterator()) D.for(Iterator I;list.iterator();i.hasNext())
2.下列关于Math类说法错误的是 答案: A.java.lang.Math类是final类,因此不能被其他类继承 B.java.lang.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象 C.java.lang.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用 D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值
3.以下哪个方法是Math类中定义的? 答案: A.absolute() B.log() C.cosine() D.sine()
4.定义在Math类上的round(double d)方法的返回值类型是什么? 答案: A.char B.int C.long D.double
5.以下哪个方法用于计算平方根? 答案:B A.squareRoot() B.sqrt() C.root() D.sqr() 6.调用Math.random()方法最有可能输出以下哪些结果? 答案:D A.-0.12和0.56E3 B.0.12和1.1E1 C.-23.45和0.0 D.0.356和0.03
7."给出以下代码,为了结果输出-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); } }" 答案: A A.floor() B.ceil() C.round() D.abs()
8.以下哪些是Collection接口的子接口? 答案:BD A.Dictionary B.List C.Map D.Set
9.以下哪些有关Vector类的描述是正确的? 答案:C A.该类是个public类 B.该类是个final类 C.该类实现了List接口 D.该类可以序列化
10.表示键值对概念的接口是哪项? 答案:D A.Set B.List C.Collection D.Map
11.以下哪些是定义在java.io包中的抽象类? 答案: A.InputStream B.PrintStream C.Reader D.FileInputStream
12.创建一个只能存放String的泛型ArrayList的语句是哪项? 答案:B A.ArrayList al = new ArrayList(); B.ArrayList al = new ArrayList(); C.ArrayList al = new ArrayList(); D.ArrayList al = new List();
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 Exception C.输出Caught Exception D.输出Caught Runtime Exception和Caught Exception 14."现有: public class Example {
public static void main(String[] args) { TreeSet s = new TreeSet(); s.add(""one""); s.add(""two""); // 插入代码处 for (String s2 : sorted) { System.out.print(s2 + "" ""); } } } 和四个代码片段: s1:SortedSet sorted = s.tailSet(s.first()); s2:SortedSet sorted = s.tailSet(s.first()); s3:SortedSet sorted = (SortedSet)s.tailSet(s.first()); s4:SortedSet sorted = (SortSet)s.tailSet(s.first()); 分别插入到插入代码处,哪项可以编译? " 答案: A.S2 B.S2和S3 C.S2和S4 D.S2、S3和S4
15.以下哪些语句用于创建一个Map实例? 答案: D A.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.以下哪些类提供了创建一个目录的方法? 答案:A A.File B.DataOutput C.Directory D.FileDescriptor
18."以下代码的执行结果是? public 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文件已经存在,则一个异常被抛出
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或者BufferedReader C.reader可以使FileReader类型,但不能使BufferedReader类型 D.reader可以使BufferedReader类型,但不能使FileReader类型
22.以下说法错误的是? 答案:C A.Java中接口不能被private或Protected修饰符修饰 B.Java中一个类可以实现多个接口,但是只能继承一个父类 C.接口中定义的成员变量,即使不说明,默认均是public\static\final的 D.final\static\native关键字不能修饰接口,
23.List接口的特点是哪项? 答案:C A.不允许重复元素,元素有顺序 B.允许重复元素,元素无顺序 C.允许重复元素,元素有顺序 D.不允许重复元素,元素无顺序
24.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字? 答案:D A.throw B.catch C.finally D.throws
25.以下哪些方法在Class类中定义? 答案: A.getConstructors()