最新精选2020年JAVASE综合测试题库188题(含标准答案)
- 格式:doc
- 大小:205.00 KB
- 文档页数:53
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()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.round(Float.MAX_V ALUE));}}"答案:BA.输出Integer.MAX_V ALUEB.输出一个最接近Float.MAX_V ALUE的整数C.编译失败D.运行时输出异常信息4."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息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."给出以下代码,为了结果输出-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."给出以下代码,请问在程序的第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]));8.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快9.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set10.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set11.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法12.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序13."以下代码的输出结果是什么?选择所有的正确答案。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map2.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double3.以下哪个方法用于计算平方根?答案: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) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息6."以下代码的运行结果是什么?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."给出以下代码,请问在程序的第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]));8."以下代码执行结果是?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不是有效的参数9.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快10.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set11.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor12.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set13."下列代码的执行结果是?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.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的语句是哪项?A.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."下列代码执行后的输出是哪项?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]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."对以下两个代码片段说法正确的是?代码片段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抛出异常23.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化24."现有代码如下: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.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对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.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有30."当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 done31."下列代码的执行结果是?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.输出432.以下哪些描述是正确的?答案: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类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()35.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException36."以下代码的输出结果是什么?选择所有的正确答案。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码执行结果是?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不是有效的参数2."关于以下代码正确的说法是: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行编译错误3."现有如下代码:public class Example {public static void main(String[] args) {try {System.out.println(""before"");。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码执行结果是?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不是有效的参数2."以下代码中,如果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.以上都不对3."以下代码执行结果是什么?class Example {public static String output = """";public static void foo(int i) {。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map2.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()3.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.034."以下代码的输出结果是什么?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) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息6."以下代码的运行结果是什么?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."以下代码执行结果是?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不是有效的参数10.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快11."现有: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.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set13.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值14.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序15.创建一个只能存放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>();16."下列代码执行后的输出是哪项?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]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.以下哪些语句用于创建一个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) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();21.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法22."给出以下代码,改程序的执行结果是?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.打印输出023.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化24."下面代码的执行结果是?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.编译失败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);} catch (Exception e) {System.out.println(""Exception"");}}}"答案:DA.编译失败B.输出ExceptionC.输出InfinityD.输出NaN27."现有如下代码: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.编译失败28.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类29."关于以下代码,说法正确的是?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"30.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有31."当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 done32."下列代码的执行结果是?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.输出433."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息34.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double35."现有如下代码: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和d36.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()37."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性38."关于以下代码,说法正确的是?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"39."给出以下代码: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 Exception40."给出以下代码,执行结果是?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.输出Try41."以下代码中,如果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.以上都不对42."以下代码执行结果是什么?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.输出1432343."以下代码执行结果是?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.代码编译成功44."关于以下代码正确的说法是: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行编译错误45."现有如下代码: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 catch46.以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.PrintStreamC.ReaderD.FileInputStream47."现有代码如下: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 middle48.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入49.以下那种初始化数组的方式是错误的?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.以上写法都正确50.以下哪些语句正确?答案: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];51.以下哪些是初始化数组的正确形式?答案: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};52.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; 答案:DCA.s[10] 为 ""B.s[9] 为 nullC.s[0] 为未定义D.s.length 为1053.数组索引从几开始?答案:AA.0B.1C.-1D.随便54.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()D.a.len55.假设存在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++){}56."以下给出代码运行后的结果是?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 257."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null58."现有: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{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null60.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以61."以下程序执行结果是?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,yy62.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程63.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()64."以下代码的执行结果是?public class Example implements Runnable {public static void main(String args[]) {Example ex = new Example();Thread t = new Thread(ex);t.start();}void run() {System.out.print(""pong"");}}"答案:A.输出pongB.运行时输出异常信息C.运行后无任何输出D.编译失败65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:public void run() {System.out.print(""go"");}执行:t.start();t.start();t.run();后结果是什么?"答案:A.go goB.go go goC.go之后跟着一个异常D.go go之后跟着一个异常66.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对67.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。
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.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException5."现有代码如下: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 middle6."下面代码的执行结果是?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.编译失败7.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行8."关于以下代码,说法正确的是?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"9."以下代码中,如果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.以上都不对10."以下代码执行结果是什么?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.输出1432311.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序12."关于以下代码正确的说法是: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行编译错误13."当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 done14.Java语言中异常的分类是哪项?A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常15.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值16.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()17.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double18.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.0319."以下代码的输出结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.round(Float.MAX_V ALUE));}}"A.输出Integer.MAX_V ALUEB.输出一个最接近Float.MAX_V ALUE的整数C.编译失败D.运行时输出异常信息20."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息21."以下代码的运行结果是什么?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.022.定义在Object类上的hashCode()方法的返回值类型是什么?答案:cA.charB.longC.intD.float23."以下代码执行结果是?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.代码编译成功24.以下关于Error和Exception类的描述正确的是?答案:AA.Error类和Exception类都是Throwable类的子类B.Error类是一个final类,而Exception类是一个非final类C.Exception类是一个final类,而Error类是一个非final类D.Error类和Exception类都实现了Throwable接口25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26."以下代码执行结果是什么?class Person {static void sayHello() {System.out.println(""HelloWorld!"");}}public class Example {public static void main(String[] args) {((Person) null).sayHello();}}"答案:CA.编译失败B.编译成功,运行时产生NullPointerExceptionC.输出HelloWorld!D.输出空白字符串27."以下代码的执行结果是?class RectObject {public int x;public int y;public RectObject(int x, int y) {this.x = x;this.y = y;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;final RectObject other = (RectObject) obj;if (x != other.x) {return false;}if (y != other.y) {return false;}return true;}}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());}}"答案:CA.size:1B.size:2C.size:3D.size:428."以下代码执行结果是?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:429."给出下面代码,请问该程序的运行结果是什么?interface A{int x=0;A(){x=5;}A(int s){x=s;}}"答案:CA.编译不通过,因为接口中的构造器必须用public修饰B.编译不通过,因为接口中不能超过一个以上的构造器C.编译不通过,因为接口中不能存在构造器D.编译不通过,因为接口名必须超过1个字符30.关于接口的说法,正确的是()答案:CA.接口中的方法只能在接口的实现类中实现B.接口中可定义变量成员C.接口中不能定义常量D.以上都不对31.请选择所有的正确答案。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map2."现有如下代码: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.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常5.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值6."以下代码的输出结果是什么?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.运行时输出异常信息7."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息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."现有: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.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set13."以下代码中,如果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.以上都不对14.创建一个只能存放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>();15."现有: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())16."现有如下类型: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描述c17."现有: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();18.以下哪些类提供了创建一个目录的方法?答案: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.以下有关ng.Exception异常类的正确描述有?答案:BA.该类是一个公共类B.该类是Throwable类的子类C.该类实现了Throwable接口D.该类可以序列化23.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化24."下列代码的执行结果是?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.输出425.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26.下列属于非受检异常(运行时异常)的是哪项?答案:AA.IOExceptionB.NullPointerExceptionC.OutOfMemoryErrorD.27.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,28.请问以下哪个程序代码体现了对象之间的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;}"29."给出以下代码,改程序的执行结果是?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.打印输出030."对以下两个代码片段说法正确的是?代码片段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."下列代码执行后的结果是?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.输出NaN32."关于以下代码,说法正确的是?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."以下代码执行结果是?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.代码编译成功35."现有如下代码: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) {36."以下代码执行结果是什么?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.输出1432337.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前38."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息39.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException40."如下代码执行后的输出结果是?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."现有如下代码: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和d42."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性43."关于以下代码,说法正确的是?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"44."给出以下代码: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 Exception45."给出以下代码,执行结果是?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.输出Try46.以下哪些是FileOutputSteram类的正确构造形式?答案:A.FileOutputStream(FileDescriptor fd)B.FileOutputStream(String n,boolean a)C.FileOutputStream(boolean a)D.FileOutputStream(File f)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.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型50.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以51.下面哪条语句不正确?答案: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};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.数组索引从几开始?答案:AA.0B.1C.-1D.随便56.假设存在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++){}57."以下给出代码运行后的结果是?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.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型59."下列代码的执行结果是什么?public class Example {public static void main(String[] args) {int index = 1;int[] foo = new int[3];int bar = foo[index];int baz = bar + index;System.out.println(baz);}}"答案:BA.打印输出0B.打印输出1C.打印输出2D.运行期间有异常抛出60.下面哪个是包装器类型?答案:AA.IntegerB.intC.charD.double61."以下代码执行的结果是: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.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入63."以下程序执行结果是?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() + "" "");}}}"答案:B.x,yy,123C.x yy 123D.x,yy64.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程65.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()66."以下代码的执行结果是?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.编译失败67."现有: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之后跟着一个异常68."下列代码的执行结果是?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.都不输出69.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对70."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null71.下面哪个类型是引用类型?答案:AA.EmployeeB.intC.charD.double72.以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.PrintStreamC.ReaderD.FileInputStream73.以下哪些描述是正确的?答案:A.Writer类可以使用不同的字符编码向输出流写入字符B.Writer类可以向输出流写入Unicode字符C.Writer类提供向输出流写入任意Java基本数据类型的方法D.Writer类提供向输出流写入引用数据类型的方法74.构造方法可以使用哪个访问权限修饰符?答案:AA.publicB.protectedC.privateD.都可以75.只允许子类及同包类访问某方法,使用哪个修饰符?答案:BA.publicB.protectedC.privateD.都可以76.如果类中的成员变量只可以被同一包访问,则使用如下哪个约束符? 答案:CA. privateB.publicC.protectedD.no modifier77.为了实现对属性的封装,属性使用哪个访问权限修饰符?答案:CA.publicB.protectedC.privateD.default78.以下哪个是有关封装优点的正确描述?答案:CA.只需要一个public方法B.从任何方法中没有异常抛出C.可以不需要改变接口来改变实现,以达到外部使用代码无需变动D.可以不需要改变实现来改变接口,已达到外部使用代码无需变动79.以下哪些是关于完全封装的正确描述?答案:CA.所有的变量都是私有的B.所有的方法都是私有的C.只有通过提供的方法才能访问类属性D.通过方法和变量名均可访问属性80."执行下列语句后,变量i的值是:byte i = 127; byte(-2^7 ~ 2^7-1)i += 1; (当溢出时回到最小)"答案:DA.128B.0C.-1D.-12881."下列代码在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 false82.以下哪个是10进制数124的正确的八进制表示?答案:A.0173B.0185C.0x185D.0x17383.Java语言中有多少个包装器类型?答案:BA.7B.8C.9D.无数个84.下面哪个不是引用类型?答案:DA.StringB.DoubleC.FloatD.float85.下面哪个说法正确?答案:AA.基本数据类型都可以直接使用=赋值B.引用类型绝对不能直接用=赋值,都需要使用new关键字C.String不是引用类型D.char是引用类型86.Double和double分别是什么类型?答案:BA.都是引用类型B.Double是引用类型,double是基本数据类型C.都是基本数据类型D.Double是基本数据类型,double是引用类型87.0.3==0.3f的结果是?答案:BA.trueB.falseC.D.88.0.5和0.5f的以下说法正确的式?答案:BA.都是引用类型B.Double是引用类型,double是基本数据类型C.都是基本数据类型D.Double是基本数据类型,double是引用类型89."Student s1=new Student(""John"");Student s2=new Student(""Alice"");s1=s2;System.out.println(s1.getName());输出结果为?"答案:DA.JohnB.nullC.AliceD.不能确定90."public class TestChange {/**** @param str*/public static void changeStr(String str){str=“"";}public static void main(String[] args){String str=""welcome"";changeStr(str);System.out.println(str);}}运行结果是?"答案:AA.welcomeC.nullD.welcome 91."以下程序运行的结果是: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 true92."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.javajavaCjava93.以下关于Error和Exception类的描述正确的是?答案:AA.Error类和Exception类都是Throwable类的子类B.Error类是一个final类,而Exception类是一个非final类C.Exception类是一个final类,而Error类是一个非final类D.Error类和Exception类都实现了Throwable接口94.以下哪个是10进制数123的正确的十六进制表示?答案:A.0x67B.0x123C.0x7BD.6795.对于以下说法,哪些是正确的?答案:ABA.如果package语句存在,则必须出现在源文件的非空白首行B.如果import语句存在,则必须出现在源文件的非空白首行(还有个package)C.如果main()方法存在,则必须出现在源文件的非空白首行D.如果在原文件中声明了一个public接口,则其名称必须和源文件名一致96.public class A{}中几个构造方法?答案:AA.1个B.2个C.3个97."1.public class A {2.public A(int x){}3.public static void main(String[] args) {4.A a new A();5.}6.}运行结果是什么?"答案:BA.第2行编译错误B.第4行编译错误C.第5行编译错误D.没有错误,什么也不输出98.对象用什么操作符调用属性或方法?答案:AA..B.*C.xD.%99."public class TestBlock {private int x;{System.out.println(""实例块"");}static{System.out.println(""静态块"");}public static void main(String[] args) {new TestBlock();new TestBlock();}}运行结果是?"答案:BA."静态块实例块"B."静态块实例块"C."静态块"D."实例块"100.对于内部类,以下说法错误的是答案:A.匿名内部类可以实现接口或继承其他类,但不能同时即实现接口又继承类B.匿名内部类不能有任何明确的构造器C.内部类可以定义在外部类类体中,(前面对)也可以定义在外部类的方法体中(错误),和外部类不同,内部类均能使用访问修饰符,并能使用static修饰D.在Java中,对内部类的嵌套层次没有限制101.以下关于内部类的描述哪些是正确的?答案:A.定义在内部类中的变量不能被static修饰符修饰,除非内部类本身是静态的B.定义在类中非方法中的内部类,可以访问外部类的所有变量,而不管变量的访问控制声明C.一个内部类实际上是外部类的子类D.内部类可以被private修饰符修饰102.声明包使用哪个关键字?答案:DA.packB.PackageC.bagD.package103.下面哪个是符合命名规范的包名?答案:A104.哪个包可以不导入直接使用?A.java.ioB.java.utilngD.java.sql105."以下给出代码运行后的结果是?public class Example {public static void main(String[] args) {int x=1;int y=~x+1;System.out.println(x+"" ""+y);}}"答案:CA.打印输出-1 1B.打印输出1 1C.打印输出1 -1D.打印输出-1 -1106.关于Java源代码文件,下列说法错误的是?答案:DA.一个源文件最多只能包含一个顶层的public类定义B.一个源文件可以不包含任何代码定义。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码执行结果是?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不是有效的参数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.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常4.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值5.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()6.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double7.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()8.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.039."以下代码的输出结果是什么?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.运行时输出异常信息10."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息11."以下代码执行结果是?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.onethreetwo12."给出以下代码,请问在程序的第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]));13."以下代码执行结果是什么?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.输出1432314.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快15.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set16.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化17.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序18.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()19.创建一个只能存放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>();20."以下代码的执行结果是?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.fouronethreetwo21."现有: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和S422."下列代码执行后的结果是?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.打印输出false23."给出以下代码,为了结果输出-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()24."现有如下代码: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) {25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26.请问以下哪个程序代码体现了对象之间的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;}"27."给出以下代码,改程序的执行结果是?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.打印输出028."现有以下代码: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;"29.Java语言中异常的分类是哪项?答案:CA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常30."现有代码: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.编译失败31."现有如下代码: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."当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 done36."以下代码执行结果是?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.代码编译成功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."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息39.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException40.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws41."下面代码的执行结果是?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."以下代码中,如果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.以上都不对46."现有如下类型: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描述c47.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有48."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null49.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以50.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;51.下面哪条语句不正确?答案: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};52.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];53.以下那种初始化数组的方式是错误的?答案: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.以上写法都正确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.数组索引从几开始?答案:AA.0B.1C.-1D.随便57.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len58.以下哪些语句用于创建一个Map实例?答案: DA.Map m = new Map();B.Map m = new Map(init capacity,increment capacity);C.Map m = new Map(new Collection());D.以上都不对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 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 true61.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();62."下列代码的执行结果是什么?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.运行期间有异常抛出63.从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.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()66."以下代码的执行结果是?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.编译失败67.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对68.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."给出以下代码,为了结果输出-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()2."给出以下代码: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 Exception3."以下代码中,如果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.以上都不对4."以下代码执行结果是?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.代码编译成功5."下列代码的执行结果是?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 Exception6."以下代码的输出结果是什么?选择所有的正确答案。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码执行结果是?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不是有效的参数2."关于以下代码正确的说法是: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行编译错误3."现有如下代码: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 catch4.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值5.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()6.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double7.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()8.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.039."以下代码的输出结果是什么?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.运行时输出异常信息10."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息11."现有如下类型: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描述c12."给出以下代码,请问在程序的第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]));13."给出以下代码,执行结果是?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.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快15.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set16.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set17.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序18.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()19."现有: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())20."以下代码的执行结果是?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.fouronethreetwo21."现有: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和S422.请问以下哪个程序代码体现了对象之间的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."给出以下代码,为了结果输出-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()24."请问以下代码的直接执行结果是?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."25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26."对以下两个代码片段说法正确的是?代码片段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抛出异常27."下列代码执行后的结果是?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.输出NaN28."现有如下代码: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.编译失败29.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类30."关于以下代码,说法正确的是?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"31.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有32."现有如下代码: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) {33."下列代码的执行结果是?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.输出434."以下代码执行结果是?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.代码编译成功35.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前36."以下代码执行结果是什么?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.输出1432337.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException38."现有代码如下: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 middle39."如下代码执行后的输出结果是?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(""out"");}}"答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败40."现有如下代码: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) {}}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) {//插入代码处c.put(""X"", 123);}}下列哪些插入到插入代码处能够正常编译?"答案:A.Map c = new SortedMap();B.HashMap c = new HashMap();C.SortedMap c = new TreeMap();D.Map c = new LinkedHashMap();47.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String48."下列代码的执行结果是什么?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.运行期间有异常抛出49.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;50.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];51.以下哪些是声明一个字符串数组的正确形式?答案:ABDA.String[] s;B.String []s;C.Sting [s]D.String s[]52.以下哪些语句正确?答案: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];53.以下哪些是初始化数组的正确形式?答案: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};54.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; 答案:DCA.s[10] 为 ""B.s[9] 为 nullC.s[0] 为未定义D.s.length 为1055.数组索引从几开始?答案:AA.0B.1C.-1D.随便56.假设存在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++){}57."以下给出代码运行后的结果是?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."以下代码执行结果是?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.onethreetwo59.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();60."下列代码在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 false61.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入62.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程63.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()64."以下代码的执行结果是?public class Example implements Runnable {public static void main(String args[]) {Example ex = new Example();Thread t = new Thread(ex);t.start();}void run() {System.out.print(""pong"");}}"答案:A.输出pongB.运行时输出异常信息C.运行后无任何输出D.编译失败65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:public void run() {System.out.print(""go"");}执行:t.start();t.start();t.run();后结果是什么?"答案:A.go goB.go go goC.go之后跟着一个异常D.go go之后跟着一个异常66."下列代码的执行结果是?public class Example{public static void main(String args[]) {Thread t = new Thread() {public void run() {pong();}};t.run();System.out.print(""ping"");}static void pong() {System.out.print(""pong"");}}"答案:A.pingpongB.pongpingC.pingpong和pongping都有可能D.都不输出67.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对68.Java UDP编程主要用到的两个类型是答案:A.UDPSocketB.DatagramSocketC.UDPPacketD.DatagramPacket69.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized70."以下代码运行输出的结果是什么?public class Example {public static void main(String[] args) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null71.以下哪些是关于完全封装的正确描述?答案:CA.所有的变量都是私有的B.所有的方法都是私有的C.只有通过提供的方法才能访问类属性D.通过方法和变量名均可访问属性72.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法73."现有: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){74.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型75."现有: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类型76.以下哪些是FileOutputSteram类的正确构造形式?答案:A.FileOutputStream(FileDescriptor fd)B.FileOutputStream(String n,boolean a)C.FileOutputStream(boolean a)D.FileOutputStream(File f)77.以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.PrintStreamC.ReaderD.FileInputStream78.以下哪些描述是正确的?答案:A.Writer类可以使用不同的字符编码向输出流写入字符B.Writer类可以向输出流写入Unicode字符C.Writer类提供向输出流写入任意Java基本数据类型的方法D.Writer类提供向输出流写入引用数据类型的方法79.方法可以使用哪个访问权限修饰符?答案:DA.publicB.protectedC.privateD.都可以80.构造方法可以使用哪个访问权限修饰符?答案:AA.publicB.protectedC.privateD.都可以81.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以82.为了实现对属性的封装,属性使用哪个访问权限修饰符?答案:CA.publicB.protectedC.privateD.default83.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型84."执行下列语句后,变量i的值是:byte i = 127;i = i+ 2;"答案:-127A.0B.编译不能通过C.运行时抛出异常D.-12885.char类型的取值范围是?答案:A.0-2^16B.0-2^16-1C.-2^15-2^15D.0-2^15-186.下面哪个类型是引用类型?答案:AA.EmployeeB.intC.charD.double87.Double和double分别是什么类型?答案:BA.都是引用类型B.Double是引用类型,double是基本数据类型C.都是基本数据类型D.Double是基本数据类型,double是引用类型88.0.3==0.3f的结果是?答案:BA.trueB.falseC.D.89."public class TestChange {/**** @param strpublic static void changeStr(String str){str=“"";}public static void main(String[] args){String str=""welcome"";changeStr(str);System.out.println(str);}}运行结果是?"答案:AA.welcomeC.nullD.welcome 90."以下程序运行的结果是: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 true91.下面哪个是包装器类型?答案:AA.IntegerB.intC.charD.double92.Java语言中有多少个包装器类型?答案:BA.7C.9D.无数个93.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,94.只允许子类及同包类访问某方法,使用哪个修饰符?答案:BA.publicB.protectedC.privateD.都可以95.类(外部类)可以使用哪个访问权限修饰符?答案:ABA.publicB.protectedC.privateD.default96.对象用什么操作符调用属性或方法?答案:AA..B.*C.xD.%97."public class TestBlock {private int x;{System.out.println(""实例块"");}static{System.out.println(""静态块"");}public static void main(String[] args) {new TestBlock();new TestBlock();}}运行结果是?"答案:BA."静态块实例块"B."静态块实例块实例块"C."静态块"D."实例块"98.对于内部类,以下说法错误的是答案:A.匿名内部类可以实现接口或继承其他类,但不能同时即实现接口又继承类B.匿名内部类不能有任何明确的构造器C.内部类可以定义在外部类类体中,(前面对)也可以定义在外部类的方法体中(错误),和外部类不同,内部类均能使用访问修饰符,并能使用static修饰D.在Java中,对内部类的嵌套层次没有限制99."对于以下代码,请问插入哪个语句可以访问到内部类InsideOne?public class Example {public static void main(String[] args) {EnclosingOne eo=new EnclosingOne();//插入语句处}}class EnclosingOne{public class InsideOne{}}"答案:A.InsideOne ei=new eo.InsideOne();B.InsideOne ei=EnclosingOne.new InsideOne();C.InsideOne ei=new EnclosingOne.InsideOne();D.EnclosingOne.InsideOne ei=eo.new InsideOne();100.有关匿名内部类的描述正确的是答案:A.匿名内部类没有显式构造器B.匿名内部类可以实现接口C.匿名内部类可以继承非final类D.匿名内部类可以同时实现接口和继承非final类101.声明包使用哪个关键字?答案:DA.packB.PackageC.bagD.package102.使用哪个关键字导入其他包?答案:BA.includeB.importC.exportD.package103.哪个包可以不导入直接使用?答案:CA.java.ioB.java.utilngD.java.sql104.要使用com.chinasofti包下所有类,哪条语句正确?答案:BA.import *;B.import com.chinasofti.*C.import com.chinasofti;D.import *.*;105.如果有int变量i和j,i的值为0xFFFFFFF1,j=~I,则j的值为?A.0B.1C.14D.-15106.对于以下说法,哪些是正确的?答案:ABA.如果package语句存在,则必须出现在源文件的非空白首行B.如果import语句存在,则必须出现在源文件的非空白首行(还有个package)C.如果main()方法存在,则必须出现在源文件的非空白首行D.如果在原文件中声明了一个public接口,则其名称必须和源文件名一致107.哪项是public class A{}中默认构造方法的声明?答案:bA.public A(int x){}B.public A(){}C.A(){}D.private A(){}108.以下哪个语句实现了声明一个二维整数数组?答案:CA.int[]5[5] a = new int[][];B.int a = new int[5,5];C.int []a[] = new int[5][5];D.int[][] a = new [5]int[5];109."以下代码的执行结果是?public class Example {public static void main(String[] args) {Element[] a1 = new Element[1];Element[][] a2 = new Element[2][1];Element[][][] a3 = new Element[3][3][3];System.out.print(a3[2][2][2]);a1[0] = new Element();a2[0] = a2[1] = a1;a3[0] = a3[1] = a3[2] = a2;System.out.print(a3[2][2][2]);}}class Element {答案:DA.输出0B.输出nullC.编译不能通过D.运行时输出异常110.以下哪些是声明一个数组的正确形式?答案:ACDA.int i[][];B.int i[5][5];C.int[] i[]D.int[][] a;111.数组拷贝方法在哪个类中?答案:DA.ArrayB.StringC.自定义类D.System112."为将数组myArray的长度由3改为6,现采取以下代码:int[] myArray = new int[3];myArray = new int[6];代码执行后,以下叙述哪项是正确的?"答案:DA.数组myArray的长度已由3改为6,其中前3个元素的值不变,后3个元素的值为空B.数组myArray的长度已经由3变为6,其中前三个元素的值不变,后3个元素需要经过初始化才能使用C.数组myArray的长度没有变化D.数组myArray的长度已由3改为6,原来3个元素的值全部丢失113."public class TestPass {String str = new String(""hello"");char[] ch = {'a','b','c'};public static void main(String[] args) {TestPass ex = new TestPass();ex.change(ex.str,ex.ch);System.out.print(ex.str + "" and "");System.out.print(ex.ch);private void change(String str,char[] ch) {str = ""test ok"";ch[1] = 'g';}}程序运行结果?"答案:DA.hello and abcB.hello and agC.hello and acD.hello and agc114.表达式(short)10/10.2*2运算后结果是什么类型?答案:CA.shortB.intC.doubleD.float115."一下代码运行输出结果是?public class Example {public static void main(String[] args) {System.out.println(3.0/0);}"答案:DA.编译失败B.运行时抛出异常C.0D.打印输出Infinity116."现有代码: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.编译失败117.关于Java源代码文件,下列说法错误的是?答案:DA.一个源文件最多只能包含一个顶层的public类定义B.一个源文件可以不包含任何代码定义。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()2."以下代码的输出结果是什么?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.运行时输出异常信息3."以下代码的运行结果是什么?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."给出以下代码,为了结果输出-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.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set10.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化11.以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.PrintStreamC.ReaderD.FileInputStream12.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序13.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double14.创建一个只能存放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>();15."现有: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())16."现有: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.现有int x = 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既不可以是PrintWriter类型,也不可以是BufferedWriter类型C.w可以是PrintWriter类型,但不可以是BufferedWriter类型D.w既可以是BufferedWriter类型,也可以是PrintWriter类型22.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,23.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set24."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性25.以下哪些方法在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.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有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."下列代码的执行结果是?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.输出432.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException33."现有代码如下: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 middle34.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.0335.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行36.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()37."给出以下代码: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."下列代码的执行结果是?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 Exception44.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值45.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()46.以下哪些描述是正确的?答案:A.InputStream和OutputStream类是基于字节流的B.ObjectInputStream类和ObjectOutputStream类不支持序列化的对象C.Reader和Writer是基于字符流的D.Reader类和Writer类是支持对象序列化的首选47."如下代码执行后的输出结果是?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.编译失败48.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();49.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;50.下面哪条语句不正确?答案: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};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.以下哪些是初始化数组的正确形式?答案: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};55.执行下列代码后,哪个结论是正确的 String[] s=new String[10];答案:DCA.s[10] 为 ""B.s[9] 为 nullC.s[0] 为未定义D.s.length 为1056.数组索引从几开始?答案:AA.0B.1C.-1D.随便57.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len58.以下哪些是FileOutputSteram类的正确构造形式?答案:A.FileOutputStream(FileDescriptor fd)B.FileOutputStream(String n,boolean a)C.FileOutputStream(boolean a)D.FileOutputStream(File f)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.Java语言中有多少个包装器类型?答案:BA.7B.8C.9D.无数个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.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入63.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()64."以下代码的执行结果是?public class Example implements Runnable {public static void main(String args[]) {Example ex = new Example();Thread t = new Thread(ex);t.start();}void run() {System.out.print(""pong"");}}"答案:A.输出pongB.运行时输出异常信息C.运行后无任何输出D.编译失败65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:public void run() {System.out.print(""go"");}执行:t.start();t.start();t.run();后结果是什么?"答案:A.go goB.go go goC.go之后跟着一个异常D.go go之后跟着一个异常66."下列代码的执行结果是?public class Example{public static void main(String args[]) {Thread t = new Thread() {public void run() {pong();}};t.run();System.out.print(""ping"");}static void pong() {System.out.print(""pong"");}}"答案:A.pingpongB.pongpingC.pingpong和pongping都有可能D.都不输出67.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。
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.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常5.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值6.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()7.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.038."以下代码的输出结果是什么?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.运行时输出异常信息9."以下代码的运行结果是什么?public class Example {public static void main(String[] args) {System.out.println(Math.min(0.0, -0.0));}}"答案:CA.代码编译失败B.输出0.0C.输出-0.0D.代码编译成功,但运行时输出异常信息10."给出以下代码,为了结果输出-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."以下代码执行结果是?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不是有效的参数13."以下代码中,如果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.以上都不对14.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set15.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化16.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map17.创建一个只能存放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>();18."现有: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())19."现有: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.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,23."给出以下代码,请问在程序的第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]));24.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26."现有以下代码: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.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类32.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有33."现有如下代码: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) {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.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorD.String36."以下代码执行结果是什么?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.输出1432337."请问以下代码的直接执行结果是?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"");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."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息39."现有代码如下: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 middle40."如下代码执行后的输出结果是?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."现有如下代码: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和d42."下面代码的执行结果是?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.编译失败43.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行44."关于以下代码,说法正确的是?class Example{public static void main(String[] args) throws IOException {if (args[0] == ""hello"") {throw new IOException();}}}"答案:AA.代码编译成功B.代码编译失败,因为main()方法是入口方法,不能抛出异常C.代码编译失败,因为IOException异常是系统异常,不能由应用程序抛出D.代码编译失败,因为字符串应该用equals方法判定一致性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.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor47."下列代码的执行结果是?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.输出448."下列代码的执行结果是什么?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.运行期间有异常抛出49.下面哪个是包装器类型?答案:AA.IntegerB.intC.charD.double50."下列代码在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.下面哪条语句不正确?答案: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.以下哪些是声明一个字符串数组的正确形式?答案:ABDA.String[] s;B.String []s;C.Sting [s]D.String s[]55.以下哪些语句正确?答案: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];56.以下哪些是初始化数组的正确形式?答案: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};57.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; 答案:DCA.s[10] 为 ""B.s[9] 为 nullC.s[0] 为未定义D.s.length 为1058."现有如下类型: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) {char[] c = new char[100];System.out.println(c[50]);}}"答案:DA.打印输出50B.打印输出49C.打印输出\u0000D.打印输出null60.0.5和0.5f的以下说法正确的式?答案:BA.都是引用类型B.Double是引用类型,double是基本数据类型C.都是基本数据类型D.Double是基本数据类型,double是引用类型61."给出下面代码: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.从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.以下哪个是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();}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."以下给出代码运行后的结果是?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 271.为了能够访问对封装的属性的访问和修改,方法往往用哪个修饰符修饰?答案:AA.publicB.protectedC.privateD.都可以72."以下代码的执行结果是?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文件已经存在,则一个异常被抛出73.以下说法正确的是()答案:A.RandomAccessFile类是File类的子类B.FileWriter类提供有操作基本数据类型的方法C.RandomAccessFile类提供有删除磁盘文件的方法D.File类提供有删除磁盘文件的方法74.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型75."现有: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类型76.以下哪些是FileOutputSteram类的正确构造形式?答案:A.FileOutputStream(FileDescriptor fd)B.FileOutputStream(String n,boolean a)C.FileOutputStream(boolean a)D.FileOutputStream(File f)77.以下哪些是定义在java.io包中的抽象类?答案:A.InputStreamB.PrintStreamC.ReaderD.FileInputStream78.以下哪些描述是正确的?答案:A.Writer类可以使用不同的字符编码向输出流写入字符B.Writer类可以向输出流写入Unicode字符C.Writer类提供向输出流写入任意Java基本数据类型的方法D.Writer类提供向输出流写入引用数据类型的方法79.方法可以使用哪个访问权限修饰符?答案:DA.publicB.protectedC.privateD.都可以80.属性可以使用哪个访问权限修饰符?答案:CA.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. privateB.publicC.protectedD.no modifier83."以下程序运行的结果是: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;i = i+ 2;"答案:-127A.0B.编译不能通过C.运行时抛出异常D.-12886.char类型的取值范围是?答案:A.0-2^16B.0-2^16-1C.-2^15-2^15D.0-2^15-187.以下哪个是10进制数123的正确的十六进制表示?答案:A.0x67B.0x123C.0x7BD.6788.以下哪个是10进制数124的正确的八进制表示?答案:A.0173B.0185C.0x185D.0x17389.下面哪个不是引用类型?答案:DA.StringB.DoubleC.FloatD.float90.下面哪个说法正确?A.基本数据类型都可以直接使用=赋值B.引用类型绝对不能直接用=赋值,都需要使用new关键字C.String不是引用类型D.char是引用类型91.Double和double分别是什么类型?答案:BA.都是引用类型B.Double是引用类型,double是基本数据类型C.都是基本数据类型D.Double是基本数据类型,double是引用类型92.0.3==0.3f的结果是?答案:BA.trueB.falseC.D.93."下列代码执行后的结果是?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 true94.构造方法可以使用哪个访问权限修饰符?答案:AA.publicB.protectedC.private95.以下哪个语句实现了声明一个二维整数数组?答案:CA.int[]5[5] a = new int[][];B.int a = new int[5,5];C.int []a[] = new int[5][5];D.int[][] a = new [5]int[5];96."public class TestBlock {private int x;{System.out.println(""实例块"");}static{System.out.println(""静态块"");}public static void main(String[] args) {new TestBlock();new TestBlock();}}运行结果是?"答案:BA."静态块实例块"B."静态块实例块实例块"C."静态块"D."实例块"97."public class TestBlock {private int x;{System.out.println(""实例块"");}static{System.out.println(""静态块"");}public static void main(String[] args) {}}运行结果是?"答案:AA.静态块B.无输出C."静态块实例块"D.实例块98."对于以下代码,请问插入哪个语句可以访问到内部类InsideOne? public class Example {public static void main(String[] args) {EnclosingOne eo=new EnclosingOne();//插入语句处}}class EnclosingOne{public class InsideOne{}}"答案:A.InsideOne ei=new eo.InsideOne();B.InsideOne ei=EnclosingOne.new InsideOne();C.InsideOne ei=new EnclosingOne.InsideOne();D.EnclosingOne.InsideOne ei=eo.new InsideOne();99.有关匿名内部类的描述正确的是答案:A.匿名内部类没有显式构造器B.匿名内部类可以实现接口C.匿名内部类可以继承非final类D.匿名内部类可以同时实现接口和继承非final类100.以下哪些类型的变量可以被一个内部类访问?答案:A.所有static变量B.所有final变量C.所有的实例成员变量D.只有final静态变量101.使用哪个关键字导入其他包?答案:BA.includeB.importC.exportD.package102.哪个包可以不导入直接使用?答案:CA.java.ioB.java.utilngD.java.sql103.要使用com.chinasofti包下所有类,哪条语句正确?答案:BA.import *;B.import com.chinasofti.*C.import com.chinasofti;D.import *.*;104.类(外部类)可以使用哪个访问权限修饰符?答案:ABA.publicB.protectedC.privateD.default105."给出以下代码,假设arr数组中只包含正整数值,请问下列代码段实现了什么功能?public int guessWhat(int arr[]) {int x = 0;for (int i = 0; i < arr.length; i++) {x = x < arr[i] ? arr[i] : x;}return x;答案:AA.获取数组的最大索引值B.判断数组中是否存在重复元素C.获取数组中元素个数D.获取数组中的最大元素106.下面哪个选项正确?答案:AA.int[][] a=new int[2][];B.int[2][] a=new int[2][];C.int a[2][3]=new int[][];D.int a[][]={3,4,5};107.对象用什么操作符调用属性或方法?答案:AA..B.*C.xD.%108."以下代码的执行结果是?public class Example {public static void main(String[] args) {Element[] a1 = new Element[1];Element[][] a2 = new Element[2][1];Element[][][] a3 = new Element[3][3][3]; System.out.print(a3[2][2][2]);a1[0] = new Element();a2[0] = a2[1] = a1;a3[0] = a3[1] = a3[2] = a2;System.out.print(a3[2][2][2]);}}class Element {}"答案:DA.输出0B.输出nullC.编译不能通过D.运行时输出异常109.数组拷贝方法在哪个类中?答案:DA.ArrayB.StringC.自定义类D.System110."public class TestPass {String str = new String(""hello"");char[] ch = {'a','b','c'};public static void main(String[] args) {TestPass ex = new TestPass();ex.change(ex.str,ex.ch);System.out.print(ex.str + "" and "");System.out.print(ex.ch);}private void change(String str,char[] ch) {str = ""test ok"";ch[1] = 'g';}}程序运行结果?"答案:DA.hello and abcB.hello and agC.hello and acD.hello and agc111.表达式(short)10/10.2*2运算后结果是什么类型?答案:CA.shortB.intC.doubleD.float112."一下代码运行输出结果是?public class Example {public static void main(String[] args) {System.out.println(3.0/0);答案:DA.编译失败B.运行时抛出异常C.0D.打印输出Infinity113."以下代码的执行结果是:public class Example {public static void main(String[] args) {byte x = -64;byte y = -6;System.out.println(x / y + "" "" + x % y);}"答案:DA.编译失败B.运行时抛出异常C.10 4D.10 -4114.有int变量i的值为16384,1>>33的结果为?答案:BA.运算数不符合运算符要求B.0C.8192D.-1115."以下给出代码运行后的结果是?public class Example {public static void main(String[] args) {int x=1;int y=~x+1;System.out.println(x+"" ""+y);}}"答案:CA.打印输出-1 1B.打印输出1 1C.打印输出1 -1D.打印输出-1 -1116."给出以下代码,改程序的执行结果是?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.打印输出0117.下面哪个是正确的二维数组声明?答案:DA.int[] a;B.int[2][] a;C.int a[2][3];D.int[][] a;118.Java类的属性,不能用哪个修饰符?答案:DA.publicB.protectedC.privateD.都可以119.java文件编译后,将生成什么文件?答案:CA.dllB.jarC.classD.doc。