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

18. Which Man class properly represents the relationship "Man has a best friend who is a Dog"?

A. class Man extends Dog { }

B. class Man implements Dog { }

C. class Man { private BestFriend dog; }

D. class Man { private Dog bestFriend; }

E. class Man { private Dog<bestFriend> }

F. class Man { private BestFriend<dog> }

19. Given:

11. public class Person {

12. private name;

13. public Person(String name) {

14. this.name = name;

15. }

16. public int hashCode() {

17. return 420;

18. }

19. }

Which is true?

A. The time to find the value from HashMap with a Person key depends on the size of the map.

B. Deleting a Person key from a HashMap will delete all map entries for all keys of type Person.

C. Inserting a second Person object into a HashSet will cause the first Person object to be removed as a duplicate.

D. The time to determine whether a Person object is contained in a HashSet is constant and does NOT depend on the size of the map.

20. Given :

23. Object [] myObjects = {

24. new integer(12),

25. new String("foo"),

26. new integer(5),

27. new Boolean(true)

28. };

29. Arrays.sort(myObjects);

30. for( int i=0; i<myObjects.length; i++) {

31. System.out.print(myObjects[i].toString());

32. System.out.print(" ");

33. }

What is the result?

A. Compilation fails due to an error in line 23.

B. Compilation fails due to an error in line 29.

C. A ClassCastException occurs in line 29.

D. A ClassCastException occurs in line 31.

E. The value of all four objects prints in natural order.

21. Given:

13. public class Pass {

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

15. int x 5;

16. Pass p = new Pass();

17. p.doStuff(x);

18. System.out.print(" main x = "+ x);

19. }

20.

21. void doStuff(int x) {

22. System.out.print(" doStuff x = "+ x++);

23. }

24. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. doStuffx = 6 main x = 6

D. doStuffx = 5 main x = 5

E. doStuffx = 5 main x = 6

F. doStuffx = 6 main x = 5

22. Given:

10. package com.sun.scjp;

11. public class Geodetics {

12. public static final double DIAMETER = 12756.32; // kilometers

13. }

Which two correctly access the DIAMETER member of the Geodetics class? (Choose two.)

A. import com.sun.scjp.Geodetics;

public class TerraCarta {

public double halfway() {

return Geodetics.DIAMETER/2.0;

}

}

B. import static com.sun.scjp.Geodetics;

public class TerraCarta {

public double halfway() {

return DIAMETER/2.0;

}

}

C. import static com.sun.scjp.Geodetics. *;

public class TerraCarta {

public double halfway() {

return DIAMETER/2.0;

}

}

D. package com.sun.scjp;

public class TerraCarta {

public double halfway() {

return DIAMETER/2.0;

}

}

23. Given:

10. interface Foo { int bar(); }

11. public class Sprite {

12. public int fubar( Foo foo) { return foo.bar(); }

13. public void testFoo() {

14. fubar(

15. // insert code here

16. );

17. }

18. }

Which code, inserted at line 15, allows the class Sprite to compile?

A. Foo { public int bar() { return 1; } }

B. new Foo { public int bar() { return 1; } }

C. newFoo() { public int bar(){return 1; } }

D. new class Foo { public int bar() { return 1; } }