this 关键字是一个引用,指向正在执行的对象。主要用途包括:访问实例变量和方法。构造器中引用其他构造器。内部类中访问外部类。嵌套类中访问嵌套类自己。匿名内部类中访问外部类。

Java 中 this 关键字的用法
什么是 this 关键字?
this 关键字是一个引用,它指向正在执行的对象。
this 关键字的用途
立即学习“Java免费学习笔记(深入)”;
this 关键字主要用于以下目的:
this 关键字的示例
<code class="java">class Person {
private String name;
public Person(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
}</code>在这个示例中:
this 关键字的注意事项
以上就是java中的this的用法的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号