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

72. Click the Exhibit button.

1. public class Test {

2.

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

4. boolean assert = true;

5. if(assert) {

6. System.out.println("assert is true");

7. }

8. }

9.

10. }

Given:

javac -source 1.3 Test.java

What is the result?

A. Compilation fails.

B. Compilation succeeds with errors.

C. Compilation succeeds with warnings.

D. Compilation succeeds without warnings or errors.

73. Click the Exhibit button.

1. public class Test {

2.

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

4. boolean assert = true;

5. if(assert) {

6. System.out.println("assert is true");

7. }

8. }

9.

10. }

Given:

javac -source 1.3 Test.java

What is the result?

A. Compilation fails.

B. Compilation succeeds with errors.

C. Compilation succeeds with warnings.

D. Compilation succeeds without warnings or errors.

74. Given:

23.int z=5;

24.

25. public void stuff1(int x) {

26. assert (x> 0);

27. switch(x) {

28. case 2: x= 3;

29. default: assert false; } }

30.

31. private void stuff2(int y) { assert (y < 0); }

32.

33. private void stuff3() { assert (stuff4O); }

34.

35. private boolean stuff4() { z = 6; return false; }

Which is true?

A. All of the assert statements are used appropriately.

B. Only the assert statement on line 31 is used appropriately.

C. The assert statements on lines 29 and 31 are used appropriately.

D. The assert statements on lines 26 and 29 are used appropriately.

E. The assert statements on lines 29 and 33 are used appropriately.

F. The assert statements on lines 29, 31, and 33 are used appropriately.

G. The assert statements on lines 26, 29, and 31 are used appropriately.

75. Click the Exhibit button.

SomeException:

1. public class SomeException {

2. }

Class A:

1. public class A {

2. public void doSomething() { }

3. }

Class B:

1. public class B extends A {

2. public void doSomething() throws SomeException { }

3. }

Which is true about the two classes?

A. Compilation of both classes will fail.

B. Compilation of both classes will succeed.

C. Compilation of class A will fail. Compilation of class B will succeed.

D. Compilation of class B will fail. Compilation of class A will succeed.

76. Click the Exhibit button.

Class TestException

1. public class TestException extends Exception {

2. }

Class A:

1. public class A {

3. public String sayHello(String name) throws TestException {

5. if(name == null) {

6. throw new TestException();

7. }

9. return "Hello "+ name;

10. }

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? (Choose two.)

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.