serialization
and
file I/O
you are here
4
445
import java.io.*;
public class GameCharacter implements Serializable {
int power;
String type;
String[] weapons;
public GameCharacter(int p, String t, String[] w) {
power = p;
type = t;
weapons = w;
}
public int getPower() {
return power;
}
public String getType() {
return type;
}
public String getWeapons() {
String weaponList = “”;
for (int i = 0; i < weapons.length; i++) {
weaponList += weapons[i] + “ “;
}
return weaponList;
}
}
The GameCharacter class
This is a basic
class just for testing
Serialization, and we don’t have an
actual game, but we’ll
leave that to
you to experiment.
Check to see if it worked.