Effective Java - To maintain the singleton guarantee, you have to declare all instance fields transient and provide a \'readResolve\' method. What do we achieve by declaring
try {
c=MySingleton.getInstance();
c.setState(25);
FileOutputStream fs = new FileOutputStream("testSer.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(c);
os.close();
}
You are getting 25 because you are setting that value in the object. Refer above code. I think you were expecting the answer to be 15?