this调用属性

示例:

class Person{
    private String name;
    private int age;

    public Person(String name,int age){
        this.name = name;
        this.age = age;
    }

    public String getInfo(){
        return  "姓名:" + this.name +",年龄:" + this.age;
    }
}

public class ThisDemo {
    public static void main(String[] args) {
        System.out.println(new Person("张三",28).getInfo());
    }

}

输出:

姓名:张三,年龄:28
原文地址:https://www.cnblogs.com/yrxns/p/9288026.html