this关键字的使用!

class Student{
  String name;
  int age;
  
  Student(String name,int age){
    this.name=name;
    this.age=age;	
  }
  
  Student playGame(){
  	  this.age++;
    	return this;
  }
  
  void printword(){
    System.out.println("年龄是"+this.age+"的"+this.name+"打了一天的LOL!");	
  }
}

public class Test{
  public static void main(String[] args){
    Student Hai = new Student("Xiaohai",20);
    Hai.playGame().playGame().printword();
  }
}

下面是内存的分析图

无标题

原文地址:https://www.cnblogs.com/acgpiano/p/4002759.html