Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ques-Только тут иногда ошибки мне встретились, редко, но все же.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
240 Кб
Скачать
☆

83. Click the Exhibit button.

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?

(Choose two.)

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.

84. Click the Exhibit button.

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. }

6. }

7. }

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.

85. Given:

11. public static void main(String[] args) {

12. try {

13. args=null;

14. args[0] = "test";

15. System.out.println(args[0]);

16. } catch (Exception ex) {

17. System.out.println("Exception");

18. } catch (NullPointerException npe) {

19. System.out.println("NullPointerException");

20. }

21. }

What is the result?

A. test

B. Exception

C. Compilation fails.

D. NullPointerException

86. Given:

11. static void test() throws Error {

12. if (true) throw new AssertionError();

13. System.out.print("test ");

14. }

15. public static void main(String[] args) {

16. try { test(); }

17. catch (Exception ex) { System.out.print("exception "); }

18. System.out.print("elld ");

19. }

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.

87. Given:

11. static void test() {

12. try {

13. String x=null;

14. System.out.print(x.toString() +" ");

15. }

16. finally { System.out.print("finally "); }

17. }

18. public static void main(String[] args) {

19. try { test(); }

20. catch (Exception ex) { System.out.print("exception "); }

21. }

What is the result?

A. null

B. finally

C. null finally

D. Compilation fails.

E. finally exception

88. Given:

11. static void test() throws RuntimeException {

12. try {

13. System.out.print("test ");

14. throw new RuntimeException();

15. }

16. catch (Exception ex) { System.out.print("exception "); }

17. }

18. public static void main(String[] args) {

19. try { test(); }

20. catch (RuntimeException ex) { System.out.print("runtime "); }

21. System.out.print("end ");

22. }

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.