CMS专题

单选题What is wrong with the following code?()   class MyException extends Exception {}   public class Qb4ab {   public void foo() {  try {  bar();  } finally {  baz();   } catch (MyException e) {}  }   public void bar() throws MyException {   throw new MyEx

题目
单选题
What is wrong with the following code?()   class MyException extends Exception {}   public class Qb4ab {   public void foo() {  try {  bar();  } finally {  baz();   } catch (MyException e) {}  }   public void bar() throws MyException {   throw new MyException();  }   public void baz() throws RuntimeException {   throw new RuntimeException();   }   }
A

Since the method foo() does not catch the exception generated by the method baz(), it must      declare the RuntimeException in its throws clause.

B

A try block cannot be followed by both a catch and a finally block.

C

An empty catch block is not allowed.

D

A catch block cannot follow a finally block.

E

A finally block must always follow one or more catch blocks.

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面程序输出的结果是什么? ( ) 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!

第2题:

What will the following C code do?

int *ptr;

ptr =(int *)Ox67a9;

*ptr = Oxaa55;


正确答案:
 

第3题:

What happens when you try to compile and run the following program?

class Mystery{String s;public static void main(String[] args){

Mystery m=new Mystery();m.go();}void Mystery(){s=”constructor”;}void go(){System.out.println(s);}

}()

A.this code will not compile

B.this code compliles but throws an exception at runtime

C.this code runs and “constructor” in the standard output

D.this code runs and writes “null” in the standard output


参考答案:D

第4题:

Which statements concerning the following code are true?()   class a {   public a() {}   public a(int i) { this(); }   }   class b extends a {   public boolean b(String msg) { return false; }   }   class c extends b  {  private c() { super(); }   public c(String msg) { this(); }   public c(int i) {}   }  

  • A、The code will fail to compile.
  • B、The constructor in a that takes an int as an argument will never be called as a result of constructing an     object of class b or c.
  • C、Class c has three constructors.
  • D、Objects of class b cannot be constructed.
  • E、At most one of the constructors of each class is called as a result of constructing an object of class c.

正确答案:B,C

第5题:

public class foo {   public static void main (Stringargs) {  String s;   system.out.printIn (“s=” + s);   }   }   What is the result?()

  • A、 The code compiles and “s=” is printed.
  • B、 The code compiles and “s=null” is printed.
  • C、 The code does not compile because string s is not initialized.
  • D、 The code does not compile because string s cannot be referenced.
  • E、 The code compiles, but a NullPointerException is thrown when toString is called.

正确答案:C

第6题:

What will be the output of the following C code?

main()

{

int k, num= 30;

k =(num > 5 ? (num <=10 ? 100:200): 500);

printf("%d", k);

}


正确答案:
 

第7题:

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

第8题:

You are developing a Windows Communication Foundation (WCF) service that is hosted by a Windows Forms Application.The ServiceHost instance is created in the Form Constructor.You need to ensure that the service is not blocked while the UI thread is busy.What should you do?()

A. Decorate the service implementation class with the following line of code [ServiceBehavior(UseSyncronizationContext = false)]

B. Decorate the service implementation class with the following line of code [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

C. Call the Invoke method of the form and supply a delegate.

D. Call the BeginInvoke method of the form and supply a delegate.


参考答案:A

第9题:

public class Foo {  public void main( String[] args ) {  System.out.println( “Hello” + args[0] );  }  }   What is the result if this code is executed with the command line?()

  • A、 Hello
  • B、 Hello Foo
  • C、 Hello world
  • D、 Compilation fails.
  • E、 The code does not run.

正确答案:E

第10题:

During system boot, rootvg fails to vary on, causing an LED code of 0552. What is the most likely cause for rootvg not varying on?()

  • A、Missing blv
  • B、Network problem
  • C、Wrong boot table
  • D、Corrupted file system

正确答案:D

更多相关问题