私はちょうどこのトピックから始めました。私の理解では、クラスのインスタンス変数を保存して後で使用できるようにしたい場合は、メソッドが定義されていない「シリアル化可能な」インターフェースを使用できます...継承...スーパークラスがシリアル化されていないのに対し、サブクラスはシリアル化されているとします...スーパークラスのインスタンス変数を保存できますか?? ただし、私はこれを知っています...スーパークラスのコストラクタが呼び出されて実行されます...しかし、それはどういう意味ですか? ということですか、スーパークラスのインスタンス変数を保存できません....
以下のプログラムでは...作成されたファイルには数値(43,23)または変数「身長」と「体重」のみが保存されます???
import java.io.*;
class A {
String sex;
public void gone(String sex){
this.sex = sex;
System.out.println("i m " + sex);
}
}
public class serialio1 extends A implements Serializable {
int height;
int weight;
public static void main(String[] args){
serialio1 myBox = new serialio1();
myBox.go(43,23);
try{
FileOutputStream fs = new FileOutputStream("foo.ser");
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(myBox);
os.close();
FileInputStream fileStream = new FileInputStream("foo.ser");
ObjectInputStream ms = new ObjectInputStream(fileStream);
Object one = ms.readObject();
Object two = ms.readObject();
int h = (int) one;
int w = (int) two;
ms.close();
System.out.println("saved values" + h + w);
} catch(Exception ex){
ex.printStackTrace();
}
}
public void go(int height , int weight) {
this.height = height;
this.weight = weight;
System.out.println(" height is " + height);
System.out.println(" weight is " + weight);
}
}