public class ThisDemo { String name = "cherry"; public void print(String name){ System.out.println("类中的属性 name =" + this.name); System.out.println("局部传参的属性 =" + name); } public static void main(String[] args) { ThisDemo tt = new ThisDemo(); tt.print("sakura"); } }
public class ThisDemo { int number; ThisDemo increment(){ number++; return this; } private void print(){ System.out.println("number=" + number); } public static void main(String[] args) { ThisDemo tt=new ThisDemo(); tt.increment().increment().increment().print(); } }