this 关键字
1 指针,指向调用该方法的对象!
2 thils在方法中使用的,指向对象,然后调用该对象的另外属性!
培养兴趣、扎实基础!
package obj;
public class Hello {
String s = "Hello";
public Hello(String s) {
System.out.println("s = " + s);
System.out.println("1 -> this.s = " + this.s);
this.s = s;
System.out.println("2 -> this.s = " + this.s);
}
public static void main(String[] args) {
Hello x = new Hello("HelloWorld!");
}
}
运行结果
s = HelloWorld!
1 -> this.s = Hello
2 -> this.s = HelloWorld!