我有一个抽象超类,它有两个属性:int 和 string。我已经覆盖了其中的 toString 方法及其具有一个额外属性 (LocalDate) 的子类。但是,由于某种我不明白的原因,当我打印子类 toSring 信息时,int 值会发生变化。
这是我在超类中的内容:
public abstract class File {
private int id;
private String text;
public File(int newId, String newText) throws IllegalArgumentException {
id(newId);
text(newText);
}
public int id() {
return id;
}
public void id(int e) throws IllegalArgumentException {
if (e <= 0) {
throw new IllegalArgumentException();
}
else {
id = e;
}
}
public String text() {
return text;
}
public void text(String aText) throws IllegalArgumentException {
if (aText == …Run Code Online (Sandbox Code Playgroud)