11.classa {  12. public void process() { System.out.print(”a,”); } }  13. class b extends a {  14. public void process() throws IOException {  15. super.process();  16. System.out.print(”b,”);  17. throw new IOException();  18. } }  19. public static void

题目

11.classa {  12. public void process() { System.out.print(”a,”); } }  13. class b extends a {  14. public void process() throws IOException {  15. super.process();  16. System.out.print(”b,”);  17. throw new IOException();  18. } }  19. public static void main(String[] args) {  20. try { new b().process(); }  21. catch (IOException e) { System.out.println(”Exception”); } }  What is the result?() 

  • A、 Exception
  • B、 a,b,Exception
  • C、 Compilation fails because of an error in line 20.
  • D、 Compilation fails because of an error in line 14.
  • E、 A NullPointerException is thrown at runtime.
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

1. public class GoTest {  2. public static void main(String[] args) {  3. Sente a = new Sente(); a.go();  4. Goban b = new Goban(); b.go();  5. Stone c = new Stone(); c.go();  6. }  7. } 8.  9. class Sente implements Go {  10. public void go() { System.out.println(”go in Sente.”); }  11. }  12.  13. class Goban extends Sente {  14. public void go() { System.out.println(”go in Goban”); }  15. }  16.  17. class Stone extends Goban implements Go { }  18.  19. interface Go { public void go(); }  What is the result?() 

  • A、 go in Goban     go in Sente go in Sente
  • B、 go in Sente      go in Sente go in Goban
  • C、 go in Sente     go in Goban go in Goban
  • D、 go in Goban    go in Goban go in Sente
  • E、 Compilation fails because of an error in line 17.

正确答案:C

第2题:

class Bird {  static void talk() { System.out.print("chirp "); }  }  class Parrot extends Bird {  static void talk() { System.out.print("hello "); }  public static void main(String [] args) {  Bird [] birds = {new Bird(), new Parrot()};  for( Bird b : birds)  b.talk();  }  }  结果为:() 

  • A、chirp chirp
  • B、chirp hello
  • C、hello hello
  • D、编译失败

正确答案:A

第3题:

下面的代码中方法unsafe()有异常发生,那么可以加在第一行的语句为( )。 { if(unsafe()) { //do something } else if(safe()) { //do the other) } Ⅰ:public void methodName() Ⅱ:public void methodName() throw IOException Ⅲ:public void methodName() throws IOException Ⅳ:public void methodName() throws Exception

A.Ⅲ、Ⅳ

B.Ⅱ、Ⅲ、Ⅳ

C.Ⅰ、Ⅲ

D.Ⅰ、Ⅳ


正确答案:A
解析:IOException异常类是Exception的子类。根据多态性的定义,IOException对象也可以被认为是Exception类型。还要注意,在方法声明中发出异常应用关键字throws。

第4题:

11.classA {  12. public void process() { System.out.print(”A “); } }  13. class B extends A {  14. public void process() throws RuntimeException {  15. super.process();  16. if (true) throw new RuntimeException();  17. System.out.print(“B”); }}  18. public static void main(String[] args) {  19. try { ((A)new B()).process(); }  20. catch (Exception e) { System.out.print(”Exception “); }  21. }  What is the result?() 

  • A、 Exception
  • B、 A Exception
  • C、 A Exception B
  • D、 A B Exception
  • E、 Compilation fails because of an error in line 14.
  • F、 Compilation fails because of an error in line 19.

正确答案:B

第5题:

1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()


正确答案:13423

第6题:

10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  Which code, inserted at line 15, allows the class Sprite to compile?() 

  • A、 Foo { public int bar() { return 1; } }
  • B、 new Foo { public int bar() { return 1; } }
  • C、 newFoo() { public int bar(){return 1; } }
  • D、 new class Foo { public int bar() { return 1; } }

正确答案:C

第7题:

11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?() 

  • A、 B
  • B、 The code runs with no output.
  • C、 Compilation fails because of an error in line 12.
  • D、 Compilation fails because of an error in line 15.
  • E、 Compilation fails because of an error in line 18.

正确答案:A

第8题:

class One {  public One() { System.out.print(1); }  }  class Two extends One {  public Two() { System.out.print(2); }  }  class Three extends Two {  public Three() { System.out.print(3); }  }  public class Numbers{  public static void main( String[] argv) { new Three(); }  }  What is the result when this code is executed?() 

  • A、 1
  • B、 3
  • C、 123
  • D、 321
  • E、 The code rims with no output.

正确答案:C

第9题:

11. public class Test {  12. public void foo() {  13. assert false;  14. assert false;  15. }  16. public void bar(){  17. while(true){  18. assert false;  19. }  20. assert false;  21. }  22. }  What causes compilation to fail?()  

  • A、 Line 13
  • B、 Line 14
  • C、 Line 18
  • D、 Line 20

正确答案:D

第10题:

import java.io.IOException;   public class ExceptionTest(   public static void main (Stringargs)  try (   methodA();   ) catch (IOException e) (   system.out.printIn(“Caught IOException”);  ) catch (Exception e) (   system.out.printIn(“Caught Exception”);   )   )   public void methodA () {   throw new IOException ();  }     What is the result?()  

  • A、 The code will not compile.
  • B、 The output is caught exception.
  • C、 The output is caught IOException.
  • D、 The program executes normally without printing a message.

正确答案:A

更多相关问题