/*
* this可以在一个构造方法里调用另一个构造方法。
* this通过不同的参数调用不同参数的构造方法。
* */
public class ThisTest {
ThisTest(int a){
System.out.println(a);
}
ThisTest(String b){
this(3);
//this(3,"sss");方法里this和super的调用一定要在第一行,并且不能同时出现,而且只能存在一个this或super
System.out.println(b);
}
ThisTest(int c, String d){
this("sss");
System.out.println(c+" "+d);
}
public static void main(String [] args){
ThisTest start = new ThisTest("future");
ThisTest go = new ThisTest(4,"ssss");
}
}
/* 当一个方法的参数与这个类下的一个变量同名,用this区分变量与参数。
*
* */
public class VarArgument {
int s;
public void test(int s){
this.s = s;
System.out.println(s);
}
public static void main(String [] args){
VarArgument start = new VarArgument();
start.test(9999);
}
}