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(); } }
内存分析: