import [Link].
*;
// Parent class
class Vehicles implements Serializable {
String color;
Vehicles(String color) {
[Link] = color;
}
}
// Child class Car
class Car extends Vehicles {
String name;
Car(String color, String name) {
super(color);
[Link] = name;
}
void display() {
[Link]("Color of Car: " + color);
[Link]("Name of the Car: " + name);
}
}
// Child class Bike
class Bike extends Vehicles {
String name;
Bike(String color, String name) {
super(color);
[Link] = name;
}
void display() {
[Link]("Color of the Bike: " + color);
[Link]("Name of the Bike: " + name);
}
}
// Main class
public class Test {
public static void main(String[] args) throws Exception {
Car c = new Car("Black", "BMW");
Bike b = new Bike("Green", "Royal Enfield");
// Serialization
FileOutputStream fos = new FileOutputStream("[Link]");
ObjectOutputStream oos = new ObjectOutputStream(fos);
[Link](c);
[Link](b);
[Link]();
[Link]();
// Deserialization
FileInputStream fis = new FileInputStream("[Link]");
ObjectInputStream ois = new ObjectInputStream(fis);
Car c1 = (Car) [Link]();
Bike b1 = (Bike) [Link]();
[Link]();
[Link]();
[Link]();
[Link]();
}
}
Output :