好的,问题来了!
我有一个类 GetStuff
public class GetStuff {
public GetStuff(String data) {
// stuff
}
}
在这个类中,我有一个调用第二个方法的方法 getMyStuff():
getAllMyStuff();
现在,我想扩展我的类(class),所以我会做一个:
public class GetSecondStuff extends GetStuff {
public GetSecondStuff(String data, int newData) {
super(data);
}
}
在第 2 类中,我将覆盖我的 getAllMyStuffMethod,但在该方法中,我需要使用构造函数中的 newData 参数:
private String getAllMyStuffMethod() {
if (newData==0) // do something
}
我如何在这里使用 newData ? :(
最佳答案
只需在 GetSecondStuff 类中创建一个新字段并在构造函数中分配它。然后你可以在覆盖方法中使用 newData。
关于java - 扩展类+新参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13515657/