二 附上Demo2,注释包含了this关键字相关知识点
package com.dong.four; public class TestThis { private int a ; private int b ; private int c; public TestThis(){ } public TestThis(int a,int b){ this.a = a; //此处加上this关键字就是区分成员变量和局部变量 this关键字第一个用处 this.b = b; } public TestThis(int a,int b,int c){ /*this.a=a; 此时如果不想这样写 可以按照下面的方式写 this(a,b); this.b=b;*/ this(a,b);//这个就相当于调用上面的构造方法 用处就是构造方法的调用 this.c =c; //除此之外 this关键字是不能用在 static关键字里面 } public static void main(String[] args) { // TODO Auto-generated method stub } }