this表示类中的属性
public Person(String name.int age)
{
this.name= name;
this.age=age;
}
不使用this指定本类的属性,则方法中的name其实操作的是传入的参数,而不是类中的属性,age同理
this调用构造方法
public fun()
{
打印构造新的对象
}
public Person(String name)
{
this.();
this.name=name;
}
public Person(String name,int age)
{
this.(name);
this.age=age;
}
this调用构造方法必须放在第一句
this调用本类的构造方法时本类中必须有一个无參构造方法
this表示当前对象
调用对象的方法打印this和在main中打印此对象结果一样都是引用传递的地址
对象比较
可以使用this和引用传递进行两个对象的相等判断
地址相等,两个对象相等,因为引用的是堆里的同一个地址,若地址不等,则根据内容判断