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

89. Given a method that must ensue that its parameter is not null:

11. public void someMethod(Object value) {

12. // check for null value

....

20. System.out.println(value.getClass());

21. }

What, inserted at line 12, is the appropriate way to handle a null value?

A. assert value == null;

B. assert value !null, "value is null";

C. if (value == null) {

throw new AssertionException("value is null");

D. if (value == null) {

throw new IllegalArgumentException("value is null");

90. Click the Exhibit button.

10. public class ClassA {

11. public void methodA() {

12. ClassB classB = new ClassB();

13. classB.getValue();

14. }

15. }

And:

20. class ClassB {

21. public ClassC classC;

22.

23. public String getValue() {

24. return classC.getValue();

25. }

26. }

And:

30. class ClassC {

31. public String value;

32.

33. public String getValue() {

34. value = "ClassB";

35. return value;

36. }

37. }

Given:

ClassA a = new ClassA(); a.methodA();

What is the result?

A. Compilation fails.

B. ClassC is displayed.

C. The code runs with no output.

D. An exception is thrown at runtime.

91. Given:

10. public class Foo {

11. static int[] a;

12. static { a[0]=2; }

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

14. }

Which exception or error will be thrown when a programmer attempts to run this code?

A. java.lang. StackOverflowError

B. java.lang.IllegalStateException

C. java.lang.ExceptionlnlnitializerError

D. java.lang.ArraylndexOutOfBoundsException

92. Given:

10. public class ClassA {

11. public void count(int i) {

12. count(++i);

13. }

14. }

And:

20. ClassA a = new ClassA();

21. a.count(3);

Which exception or error should be thrown by the virtual machine?

A. StackOverflowError

B. NullPointerException

C. NumberFormatException

D. IllegalArgumentException

E. ExceptionlnlnitializerError

93. Given:

1. public class Boxer1 {

2. Integer i;

3. int x;

4. public Boxer1(int y) {

5. x=i+y;

6. System.out.println(x);

7. }

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

9. new Boxer1(new Integer(4));

10. }

11. }

What is the result?

A. The value "4" is printed at the command line.

B. Compilation fails because of an error in line 5.

C. Compilation fails because of an error in line 9.

D. A NullPointerException occurs at runtime.

E. A NumberFormatException occurs at runtime.

F. An IllegalStateException occurs at runtime.

94. Given:

1. public class TestString 1 {

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

3. String str = "420";

4. str += 42;

5. System.out.print(str);

6. }

7. }

What is the output?

A. 42 B. 420

C. 462 D. 42042

E. Compilation fails. F. An exception is thrown at runtime.

95. Given:

11. class Converter {

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

13. Integer i = args[0];

14. int j = 12;

15. System.out.println("It is " + (j==i) + "that j==i.");

16. }

17. }

What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?

A. It is true that j==i.

B. It is false that j==i.

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 13