This is the code that I have been trying
import java.util.Scanner;
import java.io.*;
abstract class Account implements Serializable {
protected String accountHolderName;
protected long balance;
protected ObjectOutputStream accData;
Scanner input = new Scanner(System.in);
}
class Savings extends Account implements Serializable {
Savings() throws IOException {
System.out.print("enter your name: ");
accountHolderName = input.nextLine();
System.out.print("\n");
System.out.print("enter your balance: ");
balance = input.nextLong();
accData = new ObjectOutputStream(new FileOutputStream(accountHolderName + ".bin"));
accData.writeObject(this);
accData.close();
}
}
class Banking implements Serializable {
public static void main(String args[]) throws IOException {
Scanner input = new Scanner(System.in);
Savings savobj = new Savings();
}
}
and this is the exception I get
Exception in thread "main" java.io.NotSerializableException: java.io.ObjectOutputStream at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) at java.io.ObjectOutputStream.writeSerialData(Unknown Source) at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.writeObject(Unknown Source) at Savings.(Banking.java:22) at Banking.main(Banking.java:30)
I also tried using savobj.accData.writeObj(savobj) from main(), but I still get the same exception. What should I do?