Студопедия

КАТЕГОРИИ:

АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника


Click the Exhibit button. 2. public class Foo implements Serializable {




1. import java.io.*;

2. public class Foo implements Serializable {

3. public int x, y;

4. public Foo( int x, int y) { this.x = x; this.y = y; }

5.

6. private void writeObject( ObjectOutputStream s)

7. throws IOException {

8. s.writeInt(x); s.writeInt(y)

9. }

10.

11. private void readObject( ObjectInputStream s)

12. throws IOException, ClassNotFoundException {

13.

14. // insert code here

15.

16. }

17. }

Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?

A. s.defaultReadObject();

B. this = s.defaultReadObject();

C. y = s.readInt(); x = s.readInt();

D. x = s.readInt(); y = s.readInt();

106.Which three concerning the use of the java.io.Serializable interface are true?

(Choose three.)

A. Objects from classes that use aggregation cannot be serialized.

B. Art object serialized on one JVM can be successfully deserialized on a different JVM.

C. The values in fields with the volatile modifier will NOT survive serialization and deserialization.

D. The values in fields with the transient modifier will NOT survive serialization and deserialization.

E. It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable.

107. Given:

1. public class Threads4 {

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

3. new Threads4().go();

4. }

5. public void go() {

6. Runnable r = new Runnable() {

7. public void run() {

8. System.out.print("foo");

9. }

10. };

11. Thread t = new Thread(r);

12. t.start();

13. t.start();

14. }

15. }

What is the result?

A. Compilation fails.

B. An exception is thrown at runtime.

C. The code executes normally and prints 'foo".

D. The code executes normally, but nothing is printed.

 

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);


Поделиться:

Дата добавления: 2015-09-13; просмотров: 145; Мы поможем в написании вашей работы!; Нарушение авторских прав





lektsii.com - Лекции.Ком - 2014-2024 год. (0.006 сек.) Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав
Главная страница Случайная страница Контакты