this關(guān)鍵字!
教程里說使用this關(guān)鍵字是因?yàn)檫@段代碼:
public class Telphone{
private float screen;
private float cpu;
public void sendMessage()
{System.out.println("sendMessage");
}
public void setScreen(float screen)
{this.screen=screen;
this.sendMessage();
}
}
question1:形參screen和屬性名screen重名才使用this關(guān)鍵字的,那么如果修改形參名為其他的,那么就不會重名,這樣會出錯嗎?
question2:可以看到sendMessage方法是和setScreen方法是在同一類下的,而且不是靜態(tài)的,那么可以直接調(diào)用sendMessage方法不使用this關(guān)鍵字嗎?
2018-01-30
這些問題,你自己敲代碼,敲出來的結(jié)果,自己更記得牢。