Hi everyone,
import java.io.*;
class TestSer
{
public static void main(
String[] args)
{
SpecialSerial s = new SpecialSerial();
try{
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("fileWriter1"));
oos.writeObject(s);
oos.close();
System.out.print(++s.z +":");
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("fileWriter1"));
SpecialSerial s2 = (SpecialSerial)ois.readObject();
ois.close();
System.out.print(s2.y +":"+ s2.z);
}
catch(Exception x)
{
System.out.println("exc");
}
}
}
class SpecialSerial implements Serializable
{
transient int y = 7;
static int z = 9;
}
My doubt is how come output is "10:0:10",why is it not "10:7:9".I am applying the rule that transient and static variables cannot be serialized.Please help me.