Java this的相关介绍与用法(2)

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(); } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c118a92266a80ac2c855f4d2c7de6912.html