Book クラスと、Book を拡張する Library Book クラスがあります。ランダムアクセスファイルに情報を保存しています。Book オブジェクトをランダム アクセス ファイルに書き込む writeToFile メソッドがあります。LibraryBook クラスのメソッド writeToFile が super.writeToFile を呼び出してから、LibraryBook に固有のフィールドをファイルに書き込むようにします。これを行う適切な方法は何ですか?コードを参照してください:
book クラスのメソッド:
public void writeToFile(String fileName, long location) throws Exception {
try {
RandomAccessFile invFile = new RandomAccessFile(fileName, "rw");
// seek to correct record in file
invFile.seek(location);
// now write out the record
// write out the data in fixed length fields
// String fields must be truncated if too large
// or padded with blanks if too small
//write out all Book variable to file
invFile.writeLong(ISBN);
//etc.....
} catch (FileNotFoundException notFound) {
throw new FileNotFoundException();
} catch (IOException io) {
throw io;
}
}
Book を拡張する LibraryBook クラスのメソッド:
public void writeToFile(String fileName, long location) throws Exception {
try {
super.writeToFile(fileName, location);
RandomAccessFile invFile = new RandomAccessFile(fileName, "rw");
// seek to correct record in file
invFile.seek(location);
// now write out the record
// write out the data in fixed length fields
// String fields must be truncated if too large
// or padded with blanks if too small
//write library book variables to file
invFile.writeLong(branchID);
//etc....
invFile.close();
} catch (FileNotFoundException notFound) {
throw new FileNotFoundException();
} catch (IOException io) {
throw io;
}
}
LibraryBook の writeToFile メソッドがスーパークラス メソッドを呼び出して LibraryBook をファイルに保存できるようにコーディングするにはどうすればよいですか?