java this 关键字
来源:互联网 发布:淘宝充值平台人多吗 编辑:程序博客网 时间:2024/06/06 07:00
(1)返回调用当前方法的对象的引用
public class Leaf{
private int i = 0;
public Leaf increment(){
i++;
return this;
}
public void print(){
System.out.println("i="+i);
}
public static void main(String[] args){
Leaf l = new Leaf();
l.increment().increment().increment().print();
Leaf x = new Leaf();
x.increment().increment().print();
}
}
(2)在类的构造方法中调用类的其他构造方法
public class Person{
private String name;
private int age;
private String sex;
public Person(){
sex = "male";
}
public Person(String _name){
this();
name = _name;
}
public Person(String _name,int _age){
this(_name);
age = _age;
}
}
(3)在方法参数与成员变量相同时,用于区分参数名和成员变量名
public class Person{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
- Java this关键字,static关键字
- java 关键字this
- java中的this关键字
- java this 关键字
- Java基础: 关键字 this
- java 中的this关键字
- java中的this关键字
- java this关键字
- java中的this关键字
- Java--this关键字
- JAVA this 关键字
- JAVA关键字this
- java中的关键字this
- java 中的关键字 this
- java中this关键字
- Java中this关键字
- java中this关键字
- java之this关键字
- 自定义类加载器的实现,类加载过程
- CSU Problem 1779 错误的算法——湖南省第十一届大学生计算机程序设计竞赛
- jedate日期控件
- 不固定高度水平垂直居中
- vue 父子组件通信
- java this 关键字
- ios定制中间突出的tabBar
- Bitmap类用法 详细说明
- plsql developer 快捷查看表字段
- linux每天一命令-tar
- python错误提示,适合入门学习
- PHP 重载方法 __call()
- java super 关键字
- 《OpenGL ES 2.0 Programming Guide》第11章“最简单的MSAA”示例代码【C语言版】