niusouti.com

单选题1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the

题目
单选题
1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the code compile?()
A

 No code is necessary.

B

 throws Exception

C

 catch ( Exception e )

D

 throws RuntimeException

E

 catch ( TestException e)


相似考题
更多“1. public class Exception Test {  2. class TestException ext”相关问题
  • 第1题:

    下列哪个选项的java源文件程序段是不正确的? ( )

    A.package testpackage; public class Test{ }

    B.import java.io.*; package testpackage; public class Test{ }

    C.import java.i.*; class Person{} public class Test{ }

    D.import java.io.*; import java.awt.*; public class Test { }


    正确答案:B

  • 第2题:

    在下列源代码文件Test.java中,哪个选项是正确的类定义? ( )

    A.public class test { public int x=0; public test(int x) { this.x=x; } }

    B.public class Test { public int x=0; public Test(int x) { this.x=x; } }

    C.public class Test extends Ti,T2 { public int x=0; public Test(int x) { this.x=x; } }

    D.protected class Test extends T2 { public int x=0; public Test(int x) { this.x=x; } }


    正确答案:B

  • 第3题:

    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

  • 第4题:

    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

  • 第5题:

    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

  • 第6题:

    public class ExceptionTest {   class TestException extends Exception {}   public void runTest () throws TestException {}   public void test () /* Point X*/ {   runTest ();   }   }   At point X on line 4, which code can be added to make the code compile?()  

    • A、 Throws Exception.
    • B、 Catch (Exception e).
    • C、 Throws RuntimeException.
    • D、 Catch (TestException e).
    • E、 No code is necessary.

    正确答案:B

  • 第7题:

    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.

    正确答案:A

  • 第8题:

    多选题
    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.


    正确答案: A,C
    解析: 暂无解析

  • 第9题:

    单选题
    public class ExceptionTest {  class TestException extends Exception {}  public void runTest () throws TestException {}  public void test () /* Point X*/  {  runTest ();  }  }   At point X on line 4, which code can be added to make the code compile?()
    A

     Throws Exception.

    B

     Catch (Exception e).

    C

     Throws RuntimeException.

    D

     Catch (TestException e).

    E

     No code is necessary.


    正确答案: E
    解析: 暂无解析

  • 第10题:

    单选题
    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.


    正确答案: C
    解析: 暂无解析

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    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
    解析: 暂无解析

  • 第13题:

    在下列源代码文件Test.java中, ( )是正确的类定义。

    A.public class test{

    B.public class Test{ public int x=0;public int x=0; public test (intx) public Test (int x){ {this.x=x; this.x=x;} }} }

    C.public class Test extends T1,T2{

    D.protected class Test extends T2{ public int=0;public int x=0; public Test(int x){Public Test (int x){ this.x=x;this.x=x: }} }}


    正确答案:B

  • 第14题:

    1. public interface A {  2. public void doSomething(String thing);  3. }  1. public class AImpl implements A {  2. public void doSomething(String msg) { }  3. }  1. public class B {  2. public A doit() {  3. // more code here  4. }  5.  6. public String execute() { 7. // more code here  8. }  9. }  1. public class C extends B {  2. public AImpl doit() {  3. // more code here  4. }  5.  6. public Object execute() {  7. // more code here  8. }  9. }  Which statement is true about the classes and interfaces in the exhibit?() 

    • A、 Compilation will succeed for all classes and interfaces.
    • B、 Compilation of class C will fail because of an error in line 2.
    • C、 Compilation of class C will fail because of an error in line 6.
    • D、 Compilation of class AImpl will fail because of an error in line 2.

    正确答案:C

  • 第15题:

    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

  • 第16题:

    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

  • 第17题:

    1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the code compile?()  

    • A、 No code is necessary.
    • B、 throws Exception
    • C、 catch ( Exception e )
    • D、 throws RuntimeException
    • E、 catch ( TestException e)

    正确答案:B

  • 第18题:

    1. public class Test {  2. int x= 12;  3. public void method(int x) {  4. x+=x;  5. System.out.println(x);  6. }  7. }  Given:  34. Test t = new Test();  35. t.method(5);  What is the output from line 5 of the Test class?() 

    • A、 5
    • B、 10
    • C、 12
    • D、 17
    • E、 24

    正确答案:B

  • 第19题:

    单选题
    1. class A {  2. public String toString ()  {  3. return “4”;  4. }  5. }  6. class B extends A {  7. public String toString ()   {  8. return super.toString()  + “3”;  9. }  10. }  11. public class Test {  12.   public static void main(String[]args)  {  13.      System.out.printIn(new B());  14.      }  15. }    What is the result?()
    A

     Compilation succeeds and 4 is printed.

    B

     Compilation succeeds and 43 is printed.

    C

     An error on line 9 causes compilation to fail.

    D

     An error on line 14 causes compilation to fail.

    E

     Compilation succeeds but an exception is thrown at line 9.


    正确答案: A
    解析: 暂无解析

  • 第20题:

    单选题
    1. public class Test {  2. int x= 12;  3. public void method(int x) {  4. x+=x;  5. System.out.println(x);  6. }  7. }  Given:  34. Test t = new Test();  35. t.method(5);  What is the output from line 5 of the Test class?()
    A

     5

    B

     10

    C

     12

    D

     17

    E

     24


    正确答案: B
    解析: 暂无解析

  • 第21题:

    单选题
    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.


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    Given: 1.package test; 2. 3.class Target { 4.public String name = "hello";5.} What can directly access and change the value of the variable name?()
    A

    any class

    B

    only the Target class

    C

    any class in the test package

    D

    any class that extends Target


    正确答案: D
    解析: 暂无解析

  • 第23题:

    多选题
    1. public class A {  2. public void method1() {  3. B b=new B();  4. b.method2();  5. // more code here  6. }  7. }  1. public class B {  2. public void method2() {  3.C c=new C();  4. c.method3();  5. // more code here  6. }  7. }  1. public class C {  2. public void method3() {  3. // more code here  4. }  5. }  Given:  25. try {  26. A a=new A();  27. a.method1();  28. } catch (Exception e) {  29. System.out.print(”an error occurred”);  30. }  Which two are true if a NullPointerException is thrown on line 3 of class C?()
    A

    The application will crash.

    B

    The code on line 29 will be executed.

    C

    The code on line 5 of class A will execute.

    D

    The code on line 5 of class B will execute.

    E

    The exception will be propagated back to line 27.


    正确答案: D,C
    解析: 暂无解析

  • 第24题:

    单选题
    1. public class Exception Test {  2. class TestException extends Exception {}  3. public void runTest() throws TestException {}  4. public void test() /* Point X */ {  5. runTest();  6. }  7. }  At Point X on line 4, which code is necessary to make the code compile?()
    A

     No code is necessary.

    B

     throws Exception

    C

     catch ( Exception e )

    D

     throws RuntimeException

    E

     catch ( TestException e)


    正确答案: B
    解析: 暂无解析