新的学期要继续学习喽


public class TestThis {
int a,b,c;//成员变量abc

TestThis(int a,int b){//局部变量ab
this.a = a;//用this来区分吧成员变量a赋值到局部变量a,就近原则(当前对象离谁近指的是谁)
this.b = b;

}
TestThis(int a,int b,int c){
this(a,b);//用this在构造器中调用另一个构造器的使用,不能够自己调用自己且,必须放在构造方法的第一句
this.c = c;
}
void sing(){

}
void eat(){
this.sing();//调用本类中的sing()
System.out.println("你妈妈喊你回家吃饭");
}

public static void main(String[] args){//this不能够使用在static方法中
TestThis hi = new TestThis(2,3);
hi.eat();

}

}

原文地址:https://www.cnblogs.com/dream2060/p/10519819.html