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

61. Given:

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

12. Integer i = new Integer(1) + new Integer(2);

13. switch(i) {

14. case 3: System.out.println("three"); break;

15. default: System.out.println("other"); break;

16. }

17. }

What is the result?

A. three

B. other

C. An exception is thrown at runtime.

D. Compilation fails because of an error on line 12.

E. Compilation fails because of an error on line 13.

F. Compilation fails because of an error on line 15.

62. Given:

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

12. String str = "null';

13. if (str == null) {

14. System.out.println("null');

15. } else (str.length() == 0) {

16. System.out.println("zero");

17. } else {

18. System.out.println("some");

19. }

20. }

What is the result?

A. null

B. zero

C. some

D. Compilation fails.

E. An exception is thrown at runtime.

63. Given:

11. Float pi = new Float(3.14f);

12. if(pi>3) {

13. System.out.print("pi is bigger than 3. ");

14. }

15. else {

16. System.out.print("pi is not bigger than 3. ");

17. }

18. finally {

19. System.out.println("Have a nice day.");

20. }

What is the result?

A. Compilation fails.

B. pi is bigger than 3.

C. An exception occurs at runtime.

D. pi is bigger than 3. Have a nice day.

E. pi is not bigger than 3. Have a nice day.

64. Given:

10. int x=0;

11. int y 10;

12. do {

l3. y--;

14. ++x;

15. } while (x < 5);

16. System.out.print(x + "," + y);

What is the result?

A. 5,6

B. 5,5

C. 6,5

D. 6,6

65. Given:

25. int x=12;

26. while (x < 10) {

27. x--;

28. }

29. System.out.print(x);

What is the result?

A. 0

B. 10

C. 12

D. Line 29 will never be reached.

66. Given:

35. int x= 10;

36. do {

37. x--;

38. } while(x< 10);

How many times will line 37 be executed?

A. ten times

B. zero times

C. one to me times

D. more than ten times

67. Give:

11. public static Iterator reverse(List list) {

12. Collections.reverse(list);

13. return list.iterator();

14. }

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

16. List list = new ArrayList();

17. list.add(" 1"); list.add("2"); list.add("3");

18. for (Object obj: reverse(list))

19. System.out.print(obj + ",");

20. }

What is the result?

A. 3,2, 1,

B. 1, 2, 3,

C. Compilation fails.

D. The code runs with no output.

E. An exception is thrown at runtime.

68. Given:

11. public static Collection get() {

12. Collection sorted = new LinkedList();

13. sorted.add('B"); sorted.add("C"); sorted.add("A");

14. return sorted;

15. }

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

17. for (Object obj: get()) {

18. System.out.print(obj + ", ");

19. }

20. }

What is the result?

A. A, B, C, B. B, C, A, C. Compilation fails.

D. The code runs with no output.

E. An exception is thrown at runtime.

69. Given:

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

12. for (int i=0;i<= 10;i++){

13. if( i>6) break;

14. }

15. System.out.println(i);

16. }

What is the result?

A. 6

B. 7

C. 10

D. 11

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

70. Given:

8. public class test {

9. public static void main(String [] a) {

10. assert a.length == 1;

11. }

12. }

Which two will produce an AssertionError? (Choose two.)

A. java test

B. java -ea test

C. java test file1

D. java -ea test file1

E. java -ea test file1 file2

F. java -ea:test test file1

71. Given:

12. public class AssertStuff {

13.

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

15. int x= 5;

16. int y= 7;

17.

18. assert (x> y): "stuff";

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

20. }

21. }

And these command line invocations:

java AssertStuff

java -ea AssertStuff

What is the result?

A. passed stuff

B. stuff passed

C. passed An AssertionError is thrown with the word "stuff" added to the stack trace.

D. passed An AssertionError is thrown without the word "stuff" added to the stack trace.

E. passed An AssertionException is thrown with the word "stuff" added to the stack trace.

F. passed An AssertionException is thrown without the word "stuff" added to the stack trace.