this关键字

来源:互联网 发布:银科环企软件 编辑:程序博客网 时间:2024/06/05 00:26
/*

this语句用于构造函数之间进行相互调用

this代表本类中的对象,代表所在函数所属对象的引用

只能定义在构造函数第一行,因为初始化要先执行
*/
class person
{
private String name;
private int age; 
person(String name)
{
this.name =name;
}
person(String name,int age)
{
//this.name =name;
this(name);//p(name);
this.age =age;
}
}
1 0