java中this指的是什么
在类的方法定义中使用this关键字代表使用该方法的对象的引用。
当必须指出当前使用方法的对象是谁时要使用this。
有时使用this可以处理方法中成员变量和参数重名的情况。
this可以看作是一个变量,它的值是当前对象的引用,它指向自身的这个对象。(推荐教程:java教程)
立即学习“Java免费学习笔记(深入)”;
public class Leaf { int i = 0; public Leaf(int i) { this.i = i; } Leaf increament() { i++; return this; } void print() { System.out.println("i = " + i); } public static void main(String[] args) { Leaf leaf = new Leaf(100); leaf.increament().increament().print(); } }
以上就是java中this指的是什么的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号