【发布时间】:2016-06-05 06:39:00
【问题描述】:
我在一个名为 PlayableFighter 的 java 类中使用这个构造函数
public PlayableFighter(String name, int maxHealthPoints, int blastDamage, int physicalDamage,
int maxKi, int maxStamina, ArrayList<SuperAttack> superAttacks, ArrayList<UltimateAttack>
ultimateAttacks)
我想从一个名为 Earthling 的类中调用它,该类继承了 PlayableFighter 但我没有 superAttacks 或 UltimateAttacks 的值,所以我想将它们设置为默认值,我使用 null 但有更好的方法吗?
public Earthling(){
super("Earthling",1250,50,50,4,4,null,null);
}
【问题讨论】:
-
构造函数重载
-
不,没有更好的方法,除非您创建一个。它们都是 List 类型,因此您可以轻松传递一个空 List。我会更改参数类型以更喜欢界面。
标签: java inheritance constructor polymorphism default