我有一个抽象类 Flight。 Flight包含方法schedule(),它调用私有(private)方法schedule(final Flight f)
public void schedule()
{
schedule(this);
}
private void schedule(final Flight f)
{
new Timer().schedule(new TimerTask()
{
@Override
public void run()
{
f.checkIn();
updateList();
}
}, this.getDate());
}
现在假设我有一个扩展 Flight 的 SouthWestFlight 类
Flight f = new SouthWestFlight(); //ignore the missing params doesn't matter for example
f.schedule();
这会将 Flight 实例或 SouthWestFlight 实例作为 Schedule 方法中的参数传递吗?
最佳答案
Would this pass the instance of the Flight or the instance of SouthWestFlight as a parameter in the schedule method?
Flight
的实例正是 SouthWestFlight
的实例。您没有有 2 个不同的实例。您的 SoutWestFlight 实例是航类。实际上,您本身不能拥有 Flight
实例,因为它是抽象的。
关于java - 在抽象类中, "this"关键字是否引用父类或子类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18939597/