package Demo;
/**
* this 的值是当前对象的引用
* @author Aaron
*
*/
public class Boy {
private int age;
public Boy(int age) {
this.age = age;
}
public Boy work() {
this.sayHi();
return this;
}
public void sayHi() {
System.out.println("*");
}
public static void main(String[] args) {
new Boy(20).work();
}
}
源码
内存分析: