static void test() throws Error {  if (true) throw new Asser

题目
单选题
static void test() throws Error {  if (true) throw new AssertionError();  System.out.print(”test “);  }  public static void main(String[] args) {  try { test(); }  catch (Exception ex) { System.out.print(”exception “); }  System.out.print(”elld “);  }  What is the result?()
A

 end

B

 Compilation fails.

C

 exception end

D

 exception test end

E

 A Throwable is thrown by main.

F

 An Exception is thrown by main.

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

第1题:

给出下列的不完整的方法,则下列的哪个声明可以被加入①行完成此方法的声明? ① ② { success = connect( ); ③ if (success = = - 1 ) { ④ throw new TimedoutException( ) ⑤ } ⑥ }

A.public void method( )

B.public void method( ) throws Exception

C.public void method( ) throw TimedoutException

D.public throw TimedOutException void method( )


正确答案:B
解析:如果程序在运行的过程中抛出异常,而这个异常又不是Runtime-Exception或者Error,那么程序必须捕获这个异常进行处理或者声明抛出(throWs)该异常,捕获异常可以使用try{…}catch(){...}语句,而抛出异常在方法声明前是声明,在方法的声明后面加上throwsXxxxException,抛弃多个异常时,在各异常间使用逗号“,”分隔,题目中的程序在运行时抛出的不是一个RuntimeExeeption,所有必须捕获或者抛弃,而程序又没有捕获,所有应该在方法声明中声明抛弃。由于Exception是所有异常的父类,所有当然也可以代表RuntimeExccption了。

第2题:

下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i<3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]args){ try{ test d=new test: fun: }catch(Exception e){ System.OUt.println("error2") } } }

A.errorl:10.5

B.error2

C.errorl:10.5 error2

D.以上都不对


正确答案:C
C。【解析】try-catch块是可以嵌套分层的,并且通过异常对象的数据类型来进行匹配,以找到正确的catchblock异常错误处理代码。以下是通过异常对象的数据类型来进行匹配找到正确的catchblock的过程。①首先在抛出异常的try-catch块中查找catchblock,按顺序先与第一个catchblock块匹配,如果抛出的异常对象的数据类型与catchblock中传入的异常对象的临时变量(就是catch语句后面参数)的数据类型完全相同,或是它的子类型对象,则匹配成功,进入到catchblock中执行,否则到第2步;②如果有两个或更多的catchblock,则继续查找匹配第二个、第三个,直至最后一个catchblock,如匹配成功,则进入到对应的catchblock中执行,否则到第3步;③返回到上一级的try-catch块中,按规则继续查找对应的catchblock。如果找到,进入到对应的catchblock中执行,否则到第4步;④再到上上级的try-catch块中,如此不断递归,直到匹配到顶级的try-catch块中的最后一个catchblock,如果找到,进入到对应的catchblock中执行;否则程序将会执行terminate退出。所以本题选C。

第3题:

给出下列的不完整的方法,则下列的( )声明可以被加入①行完成此方法的声明。 ① ②{success=connect(); ③if(success==-1){ ④throw new TimedOutException(); ⑤} ⑥}

A.public void method()

B.public void method()throws Exception

C.public void method()throw TimedOutException

D.publicthrowTimedOutExceptionvoidmethod()


正确答案:B

第4题:

static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?() 

  • A、 test end
  • B、 Compilation fails.
  • C、 test runtime end
  • D、 test exception end
  • E、 A Throwable is thrown by main at runtime.

正确答案:D

第5题:

阅读下面程序 public class Test implements Runnable { public static void main(String[] args) { ______ t.start(); } public void run() { System.out.println("Hello!"); } } 程序中下画线处应填入的正确选项是

A.Test t=new Test();

B.Thread t=new Thread();

C.Thread t=new Thread(new Test());

D.Test t=new Thread();


正确答案:C

第6题:

已知如下代码: public class Test long a[]=new long[10] public static void main (String args[]{ System.out.println(a[6];} 以下( )语句是正确的。

A.Output is null.

B.When running,some error will occur.

C.When compile,some error will occur.

D.Output is 0.


正确答案:D

第7题:

给出下列的不完整的方法,则哪个声明可以被加入①行完成此方法的声明?( ) ① ② {success=connect(); ③ if(success==-1){ ④ throw new TimedOutException(); ⑤ } ⑥ }

A.public void method()

B.public void method()throws Exception

C.public void method()throw TimedOutException

D.public throw TimedOutException void method()


正确答案:B

第8题:

阅读下面程序 public class Test implements Runnable{ public static void main(String[]args){ _______________________________________; t. start(); } public void mR(){ System. out. println("Hello!"); }} 在程序下画线处填入正确选项是

A.Test t=flew Test()

B.Thread t=new Thread();

C.Thread t=new Thread(new Test());

D.Test t=new Thread();


正确答案:C
解析:根据t. start()可知t应该是一个Thread类,排除A)。Thread类与Test类之间没有继承关系,所以排除D)。B)没有指定创建线程的对象,因此t. start()语句不能使Test类的run方法运行。所以选C)。

第9题:

( 11 )请在下列程序的空白处,填上适当的内容:

Import java. awt. *;

Import java. util. *;

Class BufferTest{

Public static void main(string args[])

Throws IOException{

FileOutputStream unbuf=

new FileOutputStream( “ test.one ” ) ;

BufferedOutputStream buf=

new 【 11 】 (new FileOutputStream( “ test.two ” ));

System.out.println

( “ write file unbuffered: ” + time(unbuf) + “ ms ” );

System.out.println

( “ write file buffered: ” + time(buf) + “ ms ” );

}

Static int time (OutputStream os)

Throws IOException{

Date then = new Date();

for (int i=0; i<50000; i++){

os.write(1);

}

}

os.close();

return(int)(()new Date()).getTime() - then.getTime());

}


正确答案:

第10题:

public class X {  public static void main(String [] args) {  try {  badMethod();  System.out.print(“A”);  }  catch (Exception ex) {  System.out.print(“C”);  }  finally {  System.out.print(“B”);  }  System.out.print(“D”);  }  public static void badMethod() {  throw new Error();  }  }  What is the result?()  

  • A、 ABCD
  • B、 Compilation fails.
  • C、 C is printed before exiting with an error message.
  • D、 BC is printed before exiting with an error message.
  • E、 BCD is printed before exiting with an error message.

正确答案:B

更多相关问题