Question: Java problem The code below tries to store the ArrayList of Car objects in a file, but the file turns out to be empty. The

 Java problem The code below tries to store the ArrayList of
Java problem

The code below tries to store the ArrayList of Car objects in a file, but the file turns out to be empty. The problem is that Java does not know whether or not to write objects of type Car to a file. What interface should the Car class implement to fix this problem? import java.io.*: import java.util.ArrayList: class Car { String make: String model: public Car(String make. String model) { this.make = make: this.model = model: } } public class Question { public static void main(String[] args) throws Exception { ArrayList fleet = new ArrayList (): fleet.addCar ("Honda", "Civic"): fleet.addCar("Ford", "Taurus"): ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("fleet.dat"))): oos.writeObject(fleet): oos.close(): } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!