Java OCA OCP Practice Question 308

Question

Given:

 3. import java.io.*;
 4. class Vehicle { }
 5. class Wheels { }
 6. class Car extends Vehicle implements Serializable {  }
 7. class Ford extends Car { }
 8. class Dodge extends Car {
 9.     Wheels w = new Wheels();
10. }

Instances of which class(es) can be serialized? (Choose all that apply.)

  • A. Car
  • B. Ford
  • C. Dodge
  • D. Wheels
  • E. Vehicle


A and B are correct.

Note

Dodge instances cannot be serialized because they "have" an instance of Wheels, which is not serializable.

Vehicle instances cannot be serialized even though the subclass Car can be.




PreviousNext

Related