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
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
Get step-by-step solutions from verified subject matter experts
