共計(jì) 265 個(gè)字符,預(yù)計(jì)需要花費(fèi) 1 分鐘才能閱讀完成。
在 Java 中,可以使用關(guān)鍵字 this
來(lái)調(diào)用本類的方法。this
表示當(dāng)前對(duì)象,可以用于獲取當(dāng)前對(duì)象的引用,然后通過該引用調(diào)用本類的方法。例如:
public class MyClass {public void myMethod() {System.out.println(" 調(diào)用了本類的方法 ");
}
public void anotherMethod() {// 調(diào)用本類的方法
this.myMethod();}
}
在上面的例子中,anotherMethod()
方法通過 this
關(guān)鍵字調(diào)用了本類的 myMethod()
方法。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完