解答例 - 実習課題1 - 4.オブジェクトのシリアライズ
(実習課題1)
以下のクラスを作成しなさい。プログラムとして実行できなくて良い。
- 「Serializable」インタフェースを実装する
- メンバ変数は3つ以上、持つようにする
- 「transient」キーワードを持つメンバ変数を1つは持つようにする
解答例
/**
* StandardInputExample.java
* TECHSCORE Java 入出力4章 実習課題1
*
* Copyright (c) 2004 Four-Dimensional Data, Inc.
*/
package com.techscore.io.chapter4.exercise1;
import java.io.Serializable;
public class StudentExample implements Serializable {
private String id;
private transient String name;
private char course;
private int lebel;
public char getCourse() {
return course;
}
public String getId() {
return id;
}
public int getLebel() {
return lebel;
}
public String getName() {
return name;
}
public void setCourse(char course) {
this.course = course;
}
public void setId(String id) {
this.id = id;
}
public void setLebel(int lebel) {
this.lebel = lebel;
}
public void setName(String name) {
this.name = name;
}
}

