假设我有以下抽象类。
public abstract class Account {
protected String Id;
protected double balance;
public Account(String Id, double balance) {
this.Id = Id;
this.balance = balance;
}
}
以及以下子类
public class CheckingAccount {
public CheckingAccount(String Id, double balance) {
super(Id, balance)
if(super.balance > 10_000) this.balance += 200;
}
}
访问受保护成员时,子类的上下文中允许使用“this”和“super”。使用一个比另一个更好吗?'super' 明确了该字段的来源。我知道我可以在balance不指定隐式参数的情况下使用,但我只是好奇如果想指定隐式参数,它在实践中是如何使用的。
慕斯王
汪汪一只猫
相关分类