public class MySerializable implements Serializable{
private int x=10;
private static int y = 15;
public static void main(String...args){
AnotherClass a = new AnotherClass();
AnotherClass b;
//Serialize
try {
FileOutputStream fout = new FileOutputStream("MyFile.ser");
ObjectOutputStream Oout = new ObjectOutputStream(fout);
Oout.writeObject(a);
System.out.println(a.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//De-serialize
try {
FileInputStream fis = new FileInputStream("MyFile.ser");
ObjectInputStream Oin = new ObjectInputStream (fis);
b = (AnotherClass) Oin.readObject();
System.out.println(b.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}catch (ClassNotFoundException e){
e.printStackTrace();
}
}
}
class AnotherClass implements Serializable{
transient int x = 8;
static int y = 9;
@Override
public String toString() {
return "x : " + x + ", y :" + y;
}
}
क्या आप कृपया मुझे बता सकते हैं कि स्थैतिक चर को क्रमबद्ध कैसे किया जाता है ??स्थैतिक चर कैसे आते हैं?
यह जवाब सही नहीं है, स्थिर चर संग्रहीत किया जा रहा है और क्रमबद्धता द्वारा बहाल। स्थिर चर नहीं कर सकते हैं और धारावाहिक नहीं हैं; स्थैतिक क्षेत्र का मूल्य कक्षा के क्षेत्र में पूरे समय रहता है ... यह कभी भी स्मृति को कभी नहीं छोड़ा। –