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

108. Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given:

13. import java.io.*;

14. class Food {Food() { System.out.print("1"); } }

15. class Fruit extends Food implements Serializable {

16. Fruit() { System.out.print("2"); }

}

17. public class Banana2 extends Fruit {

int size = 42;

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

19. Banana2 b = new Banana2();

20. b.serializeBanana2(b); // assume correct serialization

21. b = b.deserializeBanana2(b); // assume correct

22. System.out.println(" restored "+ b.size + " "); }

23. // more Banana2 methods

24. }

What is the result?

A. Compilation fails.

B. 1 restored 42

C. 12 restored 42

D. 121 restored 42

E. 1212 restored 42

F. An exception is thrown at runtime.

109. Given:

10. public class Foo implements java.io.Serializable {

11. Private int X;

12. public int getX() { return x; }

12. publicFoo(int x){this.x=x; }

13. private void writeObject( ObjectOutputStream s)

14. throws IOException {

15. // insert code here

16. }

17. }

Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?

A. s.writeInt(x);

B. s.serialize(x);

C. s.writeObject(x);

D. s.defaultWriteObject();

110. Given:

12. NumberFormat nf= NumberFormat.getInstance();

13. nf.setMaximumFractionDigits(4);

14. nf.setMinimumFractionDigits(2);

15. String a = nf.format(3.1415926);

16. String b = nf.format(2);

Which two are true about the result if the default locale is Locale.US? (Choose two.)

A. The value of b is 2.

B. The value of a is 3.14.

C. The value of b is 2.00.

D. The value of a is 3.141.

E. The value of a is 3.1415.

F. The value of a is 3.1416.

G. The value of b is 2.0000.

111. Given:

11. double input = 314159.26;

12. NumberFormat nf= NumberFormat.getInstance(Locale.ITALIAN);

13. String b;

14. //insert code here

Which code, inserted at line 14, sets the value of b to 3 14.159,26?

A. b = nf.parse( input);

B. b = nf.format( input);

C. b = nf.equals( input);

D. b = nf.parseObject( input);

112. Given:

14. DateFormat df;

15. Date date = new Date();

16. //insert code here

17. String s = df.format( date);

Which two, inserted independently at line 16, allow the code to compile? (Choose two.)

A. df= new DateFormat();

B. df= Date.getFormatter();

C. df= date.getFormatter();

D. df= date.getDateFormatter();

E. df= Date.getDateFormatter();

F. df= DateFormat.getInstance();

G. df = DateFormat.getDateInstance();

113. Given:

12. Date date = new Date();

13. df.setLocale(Locale.ITALY);

14. String s = df.format(date);

The variable df is an object of type DateFormat that has been initialized in line 11.

What is the result if this code is run on December 14, 2000?

A. The value of s is 14-dic-2004.

B. The value of s is Dec 14, 2000.

C. An exception is thrown at runtime.

D. Compilation fails because of an error in line 13.