最新版精选2020年JAVASE综合测试版题库188题(含标准答案)
- 格式:doc
- 大小:207.50 KB
- 文档页数:54
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.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序2."下列代码的执行结果是?class Example {private void method1() throws Exception {throw new RuntimeException();}public void method2() {try {method1();} catch (RuntimeException e) {System.out.println(""Caught Runtime Exception"");} catch (Exception e) {System.out.println(""Caught Exception"");}}public static void main(String[] args) throws IOException {Example a = new Example();a.method2();}}"答案:A.代码编译失败B.输出Caught Runtime ExceptionC.输出Caught ExceptionD.输出Caught Runtime Exception和Caught Exception3."以下代码的输出结果是什么?选择所有的正确答案。
class Example {public static void main(String[] args) throws IOException { for (int i = 0; i < 10; i++) {try {try {if (i % 3 == 0)throw new Exception(""E0"");System.out.println(i);break;} catch (Exception inner) {i *= 2;if (i % 3 == 0)throw new Exception(""E1"");} finally {++i;}} catch (Exception outer) {i += 3;} finally {--i;}}}}"答案:A.4B.5C.6D.74.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常5.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()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."给出以下代码,请问在程序的第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.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor12.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化13."给出以下代码: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 Exception14.欲构造ArrayList类继承了List接口,下列哪个方法是正确的?答案:BA.ArrayList myList=new Object()B. List myList=new ArrayList()C.ArrayList myList=new List()D.List myList=new List()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."现有: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.下列属于非受检异常(运行时异常)的是哪项?答案:AA.IOExceptionB.NullPointerExceptionC.OutOfMemoryErrorD.23.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set24.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26."给出以下代码,改程序的执行结果是?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.打印输出027."现有以下代码: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;"28.Java语言中异常的分类是哪项?答案:CA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常29."现有代码:public class Example {public static void main(String[] args) {try {System.out.print(Integer.parseInt(""forty""));} catch (RuntimeException e) {System.out.println(""Runtime"");}catch (NumberFormatException e) {System.out.println(""Number"");}}}执行结果是什么?"答案:CA.输出NumberB.输出RuntimeC.输出40D.编译失败30."现有如下代码: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.编译失败31.关于异常处理,说法错误的是?A.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类32."关于以下代码,说法正确的是?class Example {public static void main(String[] args) throws IOException {System.out.println(""Before Try"");try {} catch (Throwable e) {System.out.println(""Inside Catch"");}System.out.println(""At the End"");}}"答案:BA.代码编译失败,因为无异常抛出B.代码编译失败,因为未导入IOException异常类C."输出Before TryAt the End"D."输出Inside CatchAt the End"33.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有34."关于以下代码正确的说法是: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"");8. }9.10. public static void main(String[] args) {11. Example t = new Example(4);12. }13.}"答案:A.代码在第1行编译错误B.代码在第4行编译错误C.代码在第6行编译错误D.代码在第11行编译错误35."下列代码的执行结果是?class Example {public static void main(String[] args) throws IOException { int i = 1, j = 1;try {i++;j--;if (i == j) {j++;}} catch (ArithmeticException e) {System.out.println(0);} catch (ArrayIndexOutOfBoundsException e) {System.out.println(1);} catch (Exception e) {System.out.println(2);} finally {System.out.println(3);}System.out.println(4);}}"答案:CDA.输出1B.输出2C.输出3D.输出436."给出以下代码,执行结果是?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.输出Try37.以下哪些描述是正确的?答案:CDA.try语句块后必须至少存在一个catch语句块B.try语句块后可以存在不限数量的finally语句块C.try语句块后必须至少存在一个catch语句块或finally语句块D.如果catch和finally语句块同时存在,则catch语句块必须位于finally语句块前38."请问以下代码的直接执行结果是?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."39.在方法声明中,说明该方法可能会抛出的异常列表时使用哪个关键字?答案:DA.throwB.catchC.finallyD.throws40."现有代码如下: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 middle41."现有如下代码: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 {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"46."现有: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){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 {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."下列代码在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) }}"答案:BB.输出true falseC.输出true trueD.输出false false50.数组是什么类型?答案:AA.引用类型B.基本数据类型C.不能确定D.其他类型51.下面哪条语句不正确?答案:AA.int[4] a;B.int a[];C.int[] a;D.int[] a,b;52.下面哪条语句不正确?答案:CA.int[] a={1,2,3};B.int a[]=new int[4];C.int[] a=new int[];D.int[] a=new int[]{2,3,4};53.存在Employee类,如何创建一个长度为3的Employee类型数组?答案:BA.Employee[3] e;B.Employee[] e=new Employee[3];C.Employee e[3];D.Employee[3] e=new Employee[];54.以下哪些语句正确?答案: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.以下哪些是初始化数组的正确形式?A.char c[] = {'a','b'};B.int []x[] = {{1,2,3},{1,2,3}};C.int x[3] = {1,2,3};D.int []x = {0,0,0};56.执行下列代码后,哪个结论是正确的 String[] s=new String[10]; 答案:DCA.s[10] 为 ""B.s[9] 为 nullC.s[0] 为未定义D.s.length 为1057.假设存在int型数组a,哪项是正确的增强for循环迭代该数组?答案:CA.for(int[] a){}B.for(int a){}C.for(int x:a){}D.for(int i>0;i<a.length;i++){}58."现有如下类型: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."以下程序运行的结果是: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."以下代码执行的结果是: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() + "" "");}}}"答案:A.x yyB.x,yy,123C.x yy 123D.x,yy64."以下代码的执行结果是?public class Example implements Runnable {public static void main(String args[]) {Example ex = new Example();Thread t = new Thread(ex);t.start();}void run() {System.out.print(""pong"");}}"答案:A.输出pongB.运行时输出异常信息C.运行后无任何输出D.编译失败65."现有:t是一个合法的Thread对象的引用,并且t的合法run()方法如下:public void run() {System.out.print(""go"");}执行:t.start();t.start();t.run();后结果是什么?"答案:A.go goB.go go goC.go之后跟着一个异常D.go go之后跟着一个异常66."下列代码的执行结果是?public class Example{public static void main(String args[]) {Thread t = new Thread() {public void run() {pong();}};t.run();System.out.print(""ping"");}static void pong() {System.out.print(""pong"");}}"答案:A.pingpongB.pongpingC.pingpong和pongping都有可能D.都不输出67.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对68.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1.现有int x = reader.read(),下列哪一项正确?答案:A.reader不是FileReader或者BufferedReader类型B.reader可以使FileReader或者BufferedReaderC.reader可以使FileReader类型,但不能使BufferedReader类型D.reader可以使BufferedReader类型,但不能使FileReader类型2.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map3.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序4.创建一个只能存放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>();5."下列代码执行后的输出是哪项?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"");。
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.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set2."以下代码执行结果是什么?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.输出143233."以下代码执行结果是?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.代码编译成功4."现有如下代码: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 catch5."下列代码的执行结果是?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.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常7.下列关于Math类说法错误的是答案:ng.Math类是final类,因此不能被其他类继承ng.Math类的构造器是私有的,即声明为private,不能实例化一个Math类的对象ng.Math类上定义的所有常量和方法均是public和static的,因此可以直接通过类名调用D.min()和max()方法的参数之一,如果是NaN值,则方法将返回另一个参数值8.以下哪个方法是Math类中定义的?答案:A.absolute()B.log()C.cosine()D.sine()9.定义在Math类上的round(double d)方法的返回值类型是什么?答案:A.charB.intC.longD.double10.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()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."下面代码的执行结果是?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.编译失败14.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化15.以下哪些集合接口支持重复元素存在?答案:BA.CollectionB.ListC.MapD.Set16.表示键值对概念的接口是哪项?答案:DA.SetB.ListC.CollectionD.Map17.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序18.创建一个只能存放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>();19."下列代码执行后的输出是哪项?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]20."现有: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())21."以下代码的执行结果是?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.fouronethreetwo22.所有异常的父类是哪项?答案:AA.ThrowableB.ErrorC.RuntimeExceptionD.Exception23.调用Math.random()方法最有可能输出以下哪些结果?答案:DA.-0.12和0.56E3B.0.12和1.1E1C.-23.45和0.0D.0.356和0.0324.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类25.为了保证方法的线程安全,声明方法的时候必须使用哪个修饰符?答案:A.newB.transientC.voidD.synchronized26."对以下两个代码片段说法正确的是?代码片段1:int a = 3;int b = 0;int c = a / b;代码片段2:float a = 3.0f; //Infinity(无穷大)float b = 0.0f;float c = a / b;"答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常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 {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.打印输出false29."下列代码执行后的结果是?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 true30.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,31."给出以下代码,改程序的执行结果是?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.打印输出032."现有代码:public class Example {public static void main(String[] args) {try {System.out.print(Integer.parseInt(""forty""));} catch (RuntimeException e) {System.out.println(""Runtime"");}catch (NumberFormatException e) {System.out.println(""Number"");}}}执行结果是什么?"答案:CA.输出NumberB.输出RuntimeC.输出40D.编译失败33."对以下两个代码片段说法正确的是?代码片段1:int a = 3;int b = 0;int c = a / b;代码片段2:float a = 3.0f;float b = 0.0f;float c = a / b;"答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常34."关于以下代码,说法正确的是?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"35."现有如下代码: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.编译失败36.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行37."关于以下代码,说法正确的是?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"38.关于try…catch…finally结构,描述正确的是些?答案:ACA.可以有多个catchB.只能有一个catchC.可以没有catchD.finally必须有39."当fragile()方法抛出一个IllegalArgumentException异常时,下列代码的运行结果是什么?public static void main(String[] args) throws IOException {try {fragile();} catch (NullPointerException e) {System.out.println(""NullPointerException thrown"");} catch (Exception e) {System.out.println(""Exception thrown"");} finally {System.out.println(""Done with exceptions"");}System.out.println(""myMethod is done"");}}"答案:A.输出NullPointerException thrownB.输出Exception thrownC.输出Done with ExceptionD.输出myMethod is done40."现有如下代码: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) {41.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String42."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息43.假设有自定义异常类ServiceException,那么抛出该异常的语句正确的是哪项?答案:CA.raise ServiceExceptionB.throw new ServiceException()C.throw ServiceExceptionD.throws ServiceException44."如下代码执行后的输出结果是?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.编译失败45."现有如下代码: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和d46.以下哪些类提供了创建一个目录的方法?答案:AA.FileB.DataOutputC.DirectoryD.FileDescriptor47."下列代码执行后的结果是?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.输出NaN48."下列代码的执行结果是什么?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.引用类型B.基本数据类型C.不能确定D.其他类型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.以下哪些是声明一个字符串数组的正确形式?答案:ABDA.String[] s;B.String []s;C.Sting [s]D.String s[]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.假设存在数组a,如何获得a的长度?答案:CA.a.length()B.a.len()C.a.lengthD.a.len57.假设存在int型数组a,哪项是正确的增强for循环迭代该数组?答案:CA.for(int[] a){}B.for(int a){}C.for(int x:a){}D.for(int i>0;i<a.length;i++){}58."现有:public class Example {public static void main(String[] args) {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和S459.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();60."Student s1=new Student(""John"");Student s2=new Student(""Alice"");s1=s2;System.out.println(s1.getName());输出结果为?"答案:DA.JohnB.nullC.AliceD.不能确定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.以下哪个描述是正确的?答案:A.多线程是Java语言独有的B.多线程需要多CPUC.多线程要求一个计算机拥有单独一个CPUD.Java语言支持多线程64.以下哪个是Runnable接口中定义的方法?答案:A.start()B.run()C.stop()D.yield()65."以下代码的执行结果是?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.编译失败66."现有: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之后跟着一个异常67."下列代码的执行结果是?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.都不输出68.以下哪个关于Runnable的描述是正确的?答案:A.Runnable是Java语言的一个关键字,用于修饰类,来表明该类是一个独立线程B.Runnable是一个接口,实现该接口的类对象可以提供给Thread类构造器作为创建线程的依据C.Runnable是一个类,继承该类的子类可以作为独立的线程存在D.以上皆不对69.在服务器上提供了基于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"");。
2020年JAVASE综合考试试题库188题[含答案]一、选择题1."以下代码执行结果是?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.代码编译成功2.以下哪些描述是正确的?答案: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."下列代码的运行结果是?class Example {public static void main(String[] args) throws IOException {try {return;} finally{System.out.println(""Finally"");}}}"答案:BA.无内容输出B.输出FinallyC.代码编译失败D.输出异常信息5."如下代码执行后的输出结果是?public class Example {public static void main(String[] args) {try {throw new Exception();} catch (Exception e) {try {throw new Exception();} catch (Exception e2) {System.out.println(""inner"");}System.out.println(""middle"");System.out.println(""out"");}}"答案:DA.inner outerB.middle outerC.inner middle outerD.编译失败6."现有如下代码:public class Example {public static void main(String[] args) {// anew Example().topGo();}void topGo() {// bmiddleGo();}void middleGo() {// cgo();System.out.println(""late middle"");}void go() {// dthrow new Exception();}}为了使代码能够编译通过,需要在哪个地方加入声明throws Exception?" 答案:BA.dB.c和dC.b、c和dD.a、b、c和d7."下面代码的执行结果是?class Example extends Utils {public static void main(String[] args) {try {System.out.print(new Example().getlnt(""42""));} catch (Exception e) {System.out.println(""Exc"");}int getlnt(String arg) throws Exception {return Integer.parseInt(arg);}}class Utils {int getlnt() {return 42;}}"答案:BA.NFExcB.42C.42NFExcD.编译失败8.请问以下哪些关于try…catch…finally结构中的finally语句的描述是正确的?答案:CA.只有当一个catch语句获得执行后,finally语句才获得执行B.只有当catch语句未获得执行时,finally语句才获得执行C.如果有finally语句,return语句将在finally语句执行完毕后才会返回D.只有当异常抛出时,finally语句才获得执行9."给出以下代码:class Example {public static void main(String[] args) throws IOException {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 Exception10."给出以下代码,执行结果是?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.输出Try11.以下哪些有关Vector类的描述是正确的?答案:CA.该类是个public类B.该类是个final类C.该类实现了List接口D.该类可以序列化12."以下代码执行结果是什么?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.输出1432313."现有如下代码: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) {14."关于以下代码正确的说法是: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行编译错误15."现有如下代码: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 catch16."下列代码的执行结果是?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 Exception17.Java语言中异常的分类是哪项?答案:A.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常18.以下哪个方法用于计算平方根?答案:BA.squareRoot()B.sqrt()C.root()D.sqr()19."以下代码的运行结果是什么?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.020."给出以下代码,请问在程序的第6行插入那条语句,改程序可依次打印输出11、10、9?1.public class Example {2. public static void main(String[] args) {3. double x[] = { 10.2, 9.1, 8.7 };4. int i[] = new int[3];5. for (int a = 0; a < x.length; a++) {6.7. System.out.println(i[a]);8. }9. }10.}"答案:CA.i[1] = ((int)Math.min(x[a]));B.i[1] = ((int)Math.max(x[a]));C.i[1] = ((int)Math.ceil(x[a]));D.i[1] = ((int)Math.floor(x[a]));21.下列哪些项是泛型的优点?答案:AA.不用向下强制类型转换B.代码容易编写C.类型安全D.运行速度快22."给出下面代码,请问该程序的运行结果是什么?interface A{int x=0;A(){x=5;}A(int s){x=s;}}"答案:CA.编译不通过,因为接口中的构造器必须用public修饰B.编译不通过,因为接口中不能超过一个以上的构造器C.编译不通过,因为接口中不能存在构造器D.编译不通过,因为接口名必须超过1个字符23."以下代码中,如果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.以上都不对24.以下说法错误的是?答案:CA.Java中接口不能被private或Protected修饰符修饰B.Java中一个类可以实现多个接口,但是只能继承一个父类C.接口中定义的成员变量,即使不说明,默认均是public\static\final的D.final\static\native关键字不能修饰接口,25.以下哪些方法在Class类中定义?答案:A.getConstructors()B.getPrivateMethods()C.getDeclaredFields()D.getImports()26.以下哪些描述是正确的?答案:CA.native关键字表明修饰的方法是由其他非Java语言编写的B.能够出现在Java源文件中import语句前的只有注释语句(还可以有包)C.接口中定义的方法默认是public和abstract的,不能被private或protected修饰D.构造器只能被public或protected修饰(还有private public)27.给出以下代码,请问以下哪个描述是正确的?Public XXXX extends something1,something2答案:DA.如果XXXX是一个接口,something1和something2取消掉,则代码段合法B.如果XXXX是一个类,something1和something2均是接口,则代码段合法C.如果XXXX、something1和something2均是接口,则代码段合法D.因为Java语言不支持多继承机制,所以代码段不合法28.Java语言中异常的分类是哪项?答案:AA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常29.以下关于Error和Exception类的描述正确的是?答案:AA.Error类和Exception类都是Throwable类的子类B.Error类是一个final类,而Exception类是一个非final类C.Exception类是一个final类,而Error类是一个非final类D.Error类和Exception类都实现了Throwable接口30.以下有关ng.Exception异常类的正确描述有?答案:BA.该类是一个公共类B.该类是Throwable类的子类C.该类实现了Throwable接口D.该类可以序列化31."对以下两个代码片段说法正确的是?代码片段1:int a = 3;int b = 0;int c = a / b;代码片段2:float a = 3.0f; //Infinity(无穷大)float b = 0.0f;float c = a / b;"答案:CA.执行两端代码都会抛出异常B.执行两段代码都无异常抛出C.执行两段代码,只有代码片段1抛出异常D.执行两段代码,只有代码片段2抛出异常32."下列代码执行后的结果是?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.输出NaN33."下列代码执行后的结果是?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.打印输出false34.以下哪些是catch语句能够捕获处理的异常?答案:ACA.ThrowableB.ErrorC.ExceptionD.String35.下列属于非受检异常(运行时异常)的是哪项?答案:AA.IOExceptionB.NullPointerExceptionC.OutOfMemoryErrorD.36."下列代码的执行结果是?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.输出437.请问以下哪个程序代码体现了对象之间的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;}"38."给出以下代码,改程序的执行结果是?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.打印输出039."现有以下代码: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;"40.Java语言中异常的分类是哪项?答案:CA.运行时异常和异常B.受检异常和非受检异常C.错误和异常D.错误和运行时异常41."对以下两个代码片段说法正确的是?代码片段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抛出异常42."下列代码执行后的结果是?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.输出NaN43.关于异常处理,说法错误的是?答案:CA.try…catch…finally结构中,必须有try语句块,catch语句块和finally语句块不是必须的,但至少要两者取其一B.在异常处理中,若try中的代码可能产生多种异常则可以对应多个catch语句,若catch 中的参数类型有父类子类关系,此时应该将子类放在后面,父类放在前面C.一个方法可以抛出多个异常,方法的返回值也能够是异常D.Throwable是所有异常的超类44."关于以下代码,说法正确的是?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"45."当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 done46.List接口的特点是哪项?答案:CA.不允许重复元素,元素有顺序B.允许重复元素,元素无顺序C.允许重复元素,元素有顺序D.不允许重复元素,元素无顺序47."下列代码执行后的结果是?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 true48.以下哪个语句用于获取数组中的元素个数?答案:AA.intArray.size();B.intArray.size();C.intArray.length;D.intArray.length();49."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.javajavaCjava50.下面哪个是包装器类型?答案:AA.IntegerB.intC.charD.double51."下列代码在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 false52.数组中可以存什么类型的数据?答案:CA.只能存基本数据类型B.只能存引用类型C.都可以D.都不可以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.以下那种初始化数组的方式是错误的?答案:CA.String[] names = {"zhang","wang","li"};B."String names[] = new String[3];names[2] = ""li"";names[0] = ""zhang"";names[1] = ""wang"";"C.String[3] names = {"zhang","wang","li"};D.以上写法都正确55.以下哪些语句正确?答案: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.以下哪些是Collection接口的子接口?答案:BDA.DictionaryB.ListC.MapD.Set59."以下给出代码运行后的结果是?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.Double和double分别是什么类型?答案:BA.都是引用类型B.Double是引用类型,double是基本数据类型C.都是基本数据类型D.Double是基本数据类型,double是引用类型61."下列代码的执行结果是什么?public class Example {public static void main(String[] args) {int index = 1;int[] foo = new int[3];int bar = foo[index];int baz = bar + index;System.out.println(baz);}}"答案:BA.打印输出0B.打印输出1C.打印输出2D.运行期间有异常抛出62."给出下面代码:public class Example{static int arr[] = new int[10];public static void main(String a[]){System.out.println(arr[1]);}}那个语句是正确的?"答案:DA.编译时将产生错误B.编译时正确,运行时将产生错误C.输出0D.输出null63."以下代码执行的结果是:public class Example {public static void main(String[] args) {int[] x = { 1, 2, 3 };x[1] = (x[1] > 1) ? x[2] : 0;System.out.println(x[1]);}}"答案:CA.输出1B.输出2C.输出3D.输出464.从InputStream对象中如何创建一个Reader对象?答案:A.使用InputStream类中定义的createReader()方法B.吃用Reader类中的createReader()方法C.构造一个InputStreamReader实例,将InputStream对象作为InputStreamReader类构造器的参数传入D.构造一个OutputStreamReader实例,将InputStream对象作为OutputStreamReader类构造器的参数传入65."以下代码的执行结果是?public class Example 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.编译失败66."现有: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之后跟着一个异常67."下列代码的执行结果是?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.都不输出68.在服务器上提供了基于TCP的时间服务应用,该应用使用port为6666。