Class TestException 

题目

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
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面程序输出的结果为 #include"iostream.h" class A { public: A(){cout<<"CLASSA"<<endl;} ~A() {} }; class B:public A { public: B(){cout<<"CLASSB"<<endl;} ~B() {} }; void main() { A * p; p=new B; B *q; q=new B; }

A.CLASS A CLASS B

B.CLASS A CLASS B CLASS B

C.CLASS A CLASS B CLASS A CLASS B

D.CLASS A CLASS B CLASS B CLASS B


正确答案:C
解析:每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。注意:类的实例化和构造函数、析函数的调用方式和何时调用。

第2题:

Class a = new Class(); Class b = new Class();

if(a == b) returns true or false, why?


正确答案:
               

第3题:

Given:Which statement is true?()

A. Compilation succeeds.

B. Class A does not compile.

C. The method declared on line 9 cannot be modified to throw TestException.

D. TestA compiles if line 10 is enclosed in a try/catch block that catches TestException.


参考答案:D

第4题:

Which class of Cisco access points operate under IEEE 802.3af power?()

  • A、Class A
  • B、Class 1
  • C、Class 2
  • D、Class 3
  • E、Class 4

正确答案:D

第5题:

下面程序输出的结果为( )。 #inClUde”iostream.h” Class A {public: A(){cout<<“CLASS A”<<endl;} ~A()<)}; class B:public A {public: B(){cout<<”CLASSB”<<endl;} ~B(){}}; void main() {A*p; p=new B; B *q; q=new B;}

A.CLASS A CLASS B

B.CLASS A CLASS B CLASS B

C.CLASS A ClASS B

D.CLASS A CLASS B CLASS A CLASS B CLASS B CLASS B


正确答案:C
解析: 本题考查类的继承、类的实例化和构造函数、析构函数的调用方式和何时调用。每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。

第6题:

下面程序输出的结果为

#include"iostream.h"

class A

{

public:

A( ){cout<<"CLASS A"<<endl;}

~A( ){}

};

class B:public A

{

public:

B( ){cout<<"CLASS B"<<endl;}

~B( ){}

};

void main( )

{

A*p;

p=new B;

B *q;

q=new B;

}

A.CLASS A CLASS B

B.CLASS A CLASS B CLASS B

C.CLASS A CLASS B CLASS A CLASS B

D.CLASS A CLASS B CLASS B CLASS B


正确答案:C
解析:每实例化一个类就要调用其构造函数,结束运行该实例后调用析构函数。注意:类的实例化和构造函数、析构函数的调用方式和何时调用。

第7题:

下面程序输出的结果为 #include"iostream.h” class A { public: A(){cout<<"CLASSA"<<endl;} ~A() {} }; class B:public A { public: B(){cout<<"CLASS B"<<endl;} ~B(){} }; void main() { A*p; p=new B;

A.CLASS A CLASS B CLASS B CLASS B

B.CLASS A CLASS B CLASS A CLASS B

C.CLASS A CLASS B CLASS B

D.CLASS A CLASS B


正确答案:C

第8题:

Click the Exhibit button. Given:Which statement 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

第9题:

对于下面( )类定义,可以通过“newJ_Class()”生成类J_Class的实例对象。

A、publicclassJ_Class{

publicJ_Class(void){}

}

B、publicclassJ_Class{}

C、publicclassJ_Class{

publicJ_Class(Strings){}

}

D、publicclassJ_Class{

publicvoidJ_Class(){}

publicJ_Class(Strings){}


正确答案:B

第10题:

研究下面的Java代码:  public class testException{  public static void main(String args[]){       int a[]={0,1,2,3,4};      int sum=0;      try{  for(int i=1;i<6;i++)  sum=sum+a[i];  System.out.println("sum="+sum);                 }      catch(ArrayIndexOutOfBoundsException ){                    System.out.println("数组越界");     }  finally{   System.out.println("程序结束");}  } }  输出结果将是()。       

  • A、10  数组越界  程序结束
  • B、10   程序结束
  • C、数组越界  程序结束
  • D、程序结束

正确答案:C

更多相关问题