java基础部分面试千题库(编辑修改稿)内容摘要:

e } 18. } 下列哪句代码放到第 16 行,可以导致一个 ( ) a) Alpha a = x。 b) Foo f = (Delta)x。 c) Foo f = (Alpha)x。 d) Beta b = (Beta)(Alpha)x。 37) 22. public void go() { String o =。 z: . for(int x = 0。 x 3。 x++) { for(int y = 0。 y 2。 y++) { if(x==1) break。 if(x==2 amp。 amp。 y==1) break z。 o = o + x + y。 } } (o)。 }当调用 go 方法时,输出结果是什么( ) a) 00 b) 0001 c) 000120 d) 000120221 38) 11. static void test() throws RuntimeException { try { (test )。 throw new RuntimeException()。 } catch (Exception ex) { (exception )。 } } public static void main(String[] args) { try { test()。 } catch (RuntimeException ex) { (runtime )。 } (end )。 }程序运行结果是( ) a) test end b) Compilation fails. c) test runtime end d) test exception end e) .A Throwable is thrown by main at runtime 39) 33. try { // some code here } catch (NullPointerException e1) { (a)。 } catch (Exception e2) { (b)。 } finally { (c)。 }如果程序的第 34 行会抛出一些异常,程序的运行结果是( ) a) a b) b c) c d) ac e) abc 40) 31. // some code here try { // some code here } catch (SomeException se) { // some code here } finally { // some code here } 哪种情况下 37 行的代码会执行,请选择 3 个( ) a) The instance gets garbage collected. b) The code on line 33 throws an exception. c) The code on line 35 throws an exception. d) The code on line 31 throws an exception. e) The code on line 33 executes successfully. 41) 10. int x = 0。 int y = 10。 do { y。 ++x。 } while (x 5)。 (x + , + y)。 程序运行结果是( ) a) 5, 6 b) 5, 5 c) 6, 5 d) 6, 6 42) public class Drink { public static void main(String[] args) { boolean assertsOn = true。 assert (assertsOn) : assertsOn = true。 if(assertsOn) { (assert is on)。 } } }程序运行结果是( ) a) no output b) no output assert is on c) assert is on d) assert is on An AssertionError is thrown. 43) 11. Float pi = new Float()。 if (pi 3) { (pi is bigger than 3. )。 } else { (pi is not bigger than 3. )。 } finally { (Have a nice day.)。 }程序运行结果是( ) a) Compilation fails. b) pi is bigger than 3 c) An exception occurs at runtime. d) pi is bigger than 3. Have a nice day. e) pi is not bigger than 3. Have a nice day. 44) 1. public class Boxer1{ Integer i。 int x。 public Boxer1(int y) { x = i+y。 (x)。 } public static void main(String[] args) { new Boxer1(new Integer(4))。 } }运行结果是( ) a) The value 4 is printed at the mand line. b) Compilation fails because of an error in line 5. c) A NullPointerException occurs at runtime. d) A NumberFormatException occurs at runtime. 45) 1. public class Person { private String name。 public Person(String name) { = name。 } public boolean equals(Person p) { return ()。 6. } 7. } 下列哪条语句是正确的( ) a) The equals method does NOT properly override the method. b) Compilation fails because the private attribute cannot be accessed in line 5. c) To work correctly with hashbased data structures, this class must also implement the hashCode method. d) When adding Person objects to a collection, the equals method in line 4 will prevent duplicates. 46) 1. public class Score implements Comparable { private int wins, losses。 public Score(int w, int l) { wins = w。 losses = l。 } public int getWins() { return wins。 } public int getLosses() { return losses。 } public String toString() { return + wins + , + losses +。 } // insert code here }下列哪句代码放到第 9 行,程序可以正确编译( ) a) public int pareTo(Object o){/*more code here*/} b) public int pareTo(Score other){/*more code here*/} c) public int pare(Score s1,Score s2){/*more code here*/} d) public int pare(Object o1,Object o2){/*more code here*/} 47) 3. public class Batman { int squares = 81。 public static void main(String[] args) { new Batman().go()。 } void go() { incr(++squares)。 (squares)。 } void incr(int squares) { squares += 10。 } }程序运行结果是( ) a) 81 b) 82 c) 91 d) 92 48) 15. public class Yippee { public static void main(String [] args) { for(int x = 1。 x。 x++) { (args[x] + )。 19. } 20. } 21. } 在控制台依次输入两条命令 java Yippee java Yippee 1 2 3 4 程序的运行结 果是( ) a) No output is produced. 1 2 3 b) No output is produced. 2 3 4 c) No output is produced. 1 2 3 4 d) An exception is thrown at runtime. 1 2 3 e) An exception is thrown at runtime. 2 3 4 f) An exception is thrown at runtime. 1 2 3 4 49) 13. public class Pass { public static void main(String [] args) { int x = 5。 Pass p = new Pass()。 (x)。 ( main x = + x)。 } 21. void doStuff(int x) { ( doStuff x = + x++)。 } }程序的运行结果是( ) a) Compilation fails. b) An exception is thrown at runtime. c) doStuff x = 6 main x = 6 d) doStuff x = 5 main x = 5 e) doStuff x = 5 main x = 6 f) doStuff x = 6 main x = 5 50) 3. interface Animal { void makeNoise()。 } class Horse implements Animal { Long weight = 1200L。 public void makeNoise() { (whinny)。 } } public class Icelandic extends Horse { public void makeNoise() { (vinny)。 } public static void main(String[] args) { Icelandic i1 = new Icelandic()。 Icelandic i2 = new Icelandic()。 12. Icelandic i3 = new Icelandic()。 i3 = i1。 i1 = i2。 i2 = null。 i3 = i1。 } }程序运行结束后,有几个对象符合垃圾回收的条件( ) a) 0 b) 1 c) 2 d) 3 e) 4 f) 6 51) 11. String[] elements = { for, tea, too }。 String first = ( 0) elements[0] : null。 程序运行结果是( ) a) Compilation fails. b) An exception is thrown at runtime. c) The variable first is set to null. d) The variable first is set to elements[0]. 52) 31. class Foo { public int a = 3。 public void addFive() { a += 5。 (f )。 } } class Bar ext。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。