1. class Exc0 extends Exception { }  2. class Exc1 extends Exc0 { }  3. public class Test {  4. public static void main(String args[]) {  5. try {  6. throw new Exc1();  7. } catch (Exc0 e0) {  8. System.out.println(“Ex0 caught”);  9. } catch (Exception e

题目

1. class Exc0 extends Exception { }  2. class Exc1 extends Exc0 { }  3. public class Test {  4. public static void main(String args[]) {  5. try {  6. throw new Exc1();  7. } catch (Exc0 e0) {  8. System.out.println(“Ex0 caught”);  9. } catch (Exception e) {  10. System.out.println(“exception caught”);  11. }  12. }  13. }  What is the result?()  

  • A、 Ex0 caught
  • B、 exception caught
  • C、 Compilation fails because of an error at line 2.
  • D、 Compilation fails because of an error at line 6.
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

现有:  class Parser extends Utils  { public static void main (String[]  args)    {     try{System.out.print (new Parser().getlnt("42"));      } catch (Exception e)    {      System.out.println("Exc");  }      }  int getlnt (String arg) throws Exception  {      return Integer.parselnt (arg);      }       class Utils  {  int getlnt (String arg)    {return 42;  }      }      结果为()    

  • A、 42
  • B、 Exc
  • C、 42Exc
  • D、编译失败

正确答案:D

第2题:

1. public class a {  2. public void method1() {  3. try {  4. B b=new b();  5. b.method2();  6. // more code here  7. } catch (TestException te) {  8. throw new RuntimeException(te);  9. }  10. }  11. }  1. public class b {  2. public void method2() throws TestException {  3. // more code here  4. }  5. }  1. public class TestException extends Exception {  2. }  Given:  31. public void method() {  32. A a=new a();  33. a.method1();  34. }  Which is true if a TestException is thrown on line 3 of class b?()

  • A、 Line 33 must be called within a try block.
  • B、 The exception thrown by method1 in class a is not required to be caught.
  • C、 The method declared on line 31 must be declared to throw a RuntimeException.
  • D、 On line 5 of class a, the call to method2 of class b does not need to be placed in a try/catch block.

正确答案:B

第3题:

下面程序输出的结果是什么? ( ) public class Quiz2 { public static void main(String args[]) { try {throw new MyException(); }catch(Exception e) { System.out.println("It's caught!"); }finally{ System.out.println("It's finally caught!"); } } } class MyException extends Exception{}

A.It's finally caught!

B.It's caught!

C.It's caught!/It's finally caught!

D.无输出


正确答案:C
解析:本题是对异常处理基本知识的考查。本程序中创建了一个异常类MyException,它的祖先类是Exception。在程序中,程序先发出异常MyException,下面是catch捕获异常,但是catch列表中并没有与之对应的MyExcepfion,但是有一个Exception,它是MyException的祖先类。如果有多种异常需要捕获,在安排catch语句的顺序时要注意,应该首先捕获最特殊的类,然后逐渐一般化。例如,IOExcepfion类是FileNotFoundException类的父类;就应该首先捕获FileNotFoundException异常,然后捕获IOExcepfion异常。所以运行结果是It'scaught!/It'sfinallycaught!

第4题:

public class A extends Thread {  A() {  setDaemon(true);  }  public void run() {  (new B()).start();  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“A done”);  }  class B extends Thread {  public void run() {  try {  Thread.sleep(60000);  } catch (InterruptedException x) {}  System.out.println(“B done”);  }  }  public static void main(String[] args) {  (new A()).start();  }  }   What is the result?()  

  • A、 A done
  • B、 B done
  • C、 A done B done
  • D、 B done A done
  • E、 There is no exception that the application will print anything.
  • F、 The application outputs “A done” and “B done”, in no guaranteed order.

正确答案:B

第5题:

1. public class A {  2. void A() {  3. System.out.println(“Class A”);  4. }  5. public static void main(String[] args) {  6. new A();  7. }  8. }  What is the result?()  

  • A、 Class A
  • B、 Compilation fails.
  • C、 An exception is thrown at line 2.
  • D、 An exception is thrown at line 6.
  • E、 The code executes with no output.

正确答案:E

第6题:

Class TestException  1. public class TestException extends Exception {  2. } Class a:  1. public class a {  2.  3. public String sayHello(String name) throws TestException {  4.  5. if(name == null) {  6. throw new TestException();  7. }  8.  9. return “Hello “+ name;  10. }  11.  12. }  A programmer wants to use this code in an application: 45. A a=new A();  46. System.out.println(a.sayHello(”John”));  Which two are true?()

  • A、 Class a will not compile.
  • B、 Line 46 can throw the unchecked exception TestException.
  • C、 Line 45 can throw the unchecked exception TestException.
  • D、 Line 46 will compile if the enclosing method throws a TestException.
  • E、 Line 46 will compile if enclosed in a try block, where TestException is caught.

正确答案:D,E

第7题:

1. public class Test {   2. public static void main (String args) {   3. unsigned byte b = 0;   4. b--;   5.   6. }   7. }   What is the value of b at line 5?()  

  • A、 -1
  • B、 255
  • C、 127
  • D、 Compilation will fail.
  • E、 Compilation will succeed but the program will throw an exception at line 4.

正确答案:D

第8题:

1. public class SimpleCalc {  2. public int value;  3. public void calculate() { value += 7; }  4. } And:  1. public class MultiCalc extends SimpleCalc {  2. public void calculate() { value -= 3; }  3. public void calculate(int multiplier) {  4. calculate();  5. super.calculate();  6. value *=multiplier;  7. }  8. public static void main(String[] args) {  9. MultiCalc calculator = new MultiCalc();  10. calculator.calculate(2);  11. System.out.println(”Value is: “+ calculator.value);  12. }  13. }  What is the result?() 

  • A、 Value is: 8
  • B、 Compilation fails.
  • C、 Value is: 12
  • D、 Value is: -12
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

正确答案:A

第9题:

现有  class Parser extends Utils {  public static void main (String  []  args)  {  try  {  System.out.print (new Parser () .getlnt ("42"))       }  catch (Exception e) {  System.out.println ("Exc") ;  }      }  int getlnt (String arg)  throws Exception  {     return Integer.parselnt (arg) ;      }      }  class Utils {  int getlnt ()  {  return 42;  }     }  结果是什么?()      

  • A、 42Exc
  • B、 Exc
  • C、 42
  • D、编译失败

正确答案:C

第10题:

public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  

  • A、 finally
  • B、 exception finished
  • C、 finally exception finished
  • D、 Compilation fails.

正确答案:C

更多相关问题