Assuming that the serializeBanana2 and the deserializeBanana2 methods will

Assuming that the serializebanana2 and the

This preview shows page 45 - 48 out of 102 pages.

Question 101 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 serialization21. b = b.deserializeBanana2(b); // assume correct22. System.out.println(” restored “+ b.size + “ “); }23. // more Banana2 methods24. }What is the result?
Background image
Question 102Given: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 here16. }17. }Which code fragment, inserted at line 15, will allow Foo objects to becorrectly serialized and deserialized? Question 103Given: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.) Question 104 Given:11. double input = 314159.26;
Background image
12. NumberFormat nf= NumberFormat.getInstance(Locale.ITALIAN);13. String b;14. //insert code hereWhich 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); Question 105Given:14. DateFormat df;15. Date date = new Date();16. //insert code here17. String s = df.format( date);Which two, inserted independently at line 16, allow the code tocompile? (Choose two.) Question 106Given: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 beeninitialized in line 11. What is the result if this code is run on December14, 2000?
Background image
Image of page 48

You've reached the end of your free preview.

Want to read all 102 pages?

  • Fall '15
  • Muler
  • Madrid Metro, Metropolitana di Napoli, class a, Osaka Municipal Subway, public class, public static void

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture