The height in Stu class is static. It should be 0. But it outputs 180. Can anyone tell me what's wrong? Thank you so much!
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class SerializableDemo { public static void main(String[] args) throws IOException, ClassNotFoundException { w(); r(); } private static void r() throws IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream(new FileInputStream( "d:/abc/stu")); Stu stu = (Stu) in.readObject(); System.out.println(stu); in.close(); } private static void w() throws IOException { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream( "d:/abc/stu")); out.writeObject(new Stu(1, "z3", "m", 20, 180, 80)); out.close(); } } class Stu implements Serializable { private static final long serialVersionUID = 2016L; private int id; private String name; private String gender; private int age; private static int height; private transient int weight; public Stu(int id, String name, String gender, int age, int height, int weight) { this.id = id; this.name = name; this.gender = gender; this.age = age; this.height = height; this.weight = weight; } @Override public String toString() { return "Stu [id=" + id + ", name=" + name + ", gender=" + gender + ", age=" + age + ", height=" + height + ", weight=" + weight + "]"; } }