nerdexam
Oracle

1Z0-829 · Question #20

1Z0-829 Question #20: Real Exam Question with Answer & Explanation

Sign in or unlock 1Z0-829 to reveal the answer and full explanation for question #20. The question stem and answer options stay visible for context.

Using Java I/O API

Question

Given the code fragments: class Car implements Serializable { private static long serialVersionUID = 454l; String name; public Car(String name) { this.name = name; } public String toString() { return name + " " + flag_MHC; } } class LuxuryCar extends Car { int flag_MHC; public LuxuryCar(String name, int flag_MHC) { super(name); this.flag_MHC = flag_MHC; } } // and: public static void main(String[] args) { Car b = new LuxuryCar("Wagon", 200); // line n2 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("car.ser"))); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("car.ser"))); oos.writeObject(b); System.out.println((Car)(ois.readObject())); // line n3 } Which action prints Wagon : 200?

Options

  • AAt line n1, implement the java.io.Serializable interface.
  • BAt line n3, replace readObject () with readline().
  • CAt line n3, replace Car with LuxuryCar.
  • DAt line n1, implement the java.io.AutoCloseable interface
  • EAt line n2, in the main method signature, add throws IOException, ClassCastException.
  • FAt line n2, in the main method signature, add throws IOException, ClassNotFoundException.

Unlock 1Z0-829 to see the answer

You've previewed enough free 1Z0-829 questions. Unlock 1Z0-829 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Topics

#serialization#exception handling#object I/O#inheritance
Full 1Z0-829 Practice