this关键字:
1. this用来表示全局(成员)变量。
2. 举例说明
/* * this关键字的范例 */ public class Hello { String s = "Hello"; public Hello(String s) { System.out.println("s = " + s); //调用主方法中的 new Hello("Helloword") 的参数 System.out.println("1 -> this.s = " + this.s); //调用成员变量中的 String s ="Hello" this.s = s;//把参数值赋给成员变量,成员变量的值改变 ( String s = "Helloword" ) System.out.println("2 -> this.s = " + this.s); } public static void main(String[] args) { Hello x = new Hello("HelloWorld!"); System.out.println("s=" + x.s);//验证成员变量值的改变 } }