this:看上去,用来区分局部变量和成员变量同名的情况
this:代表本类对象,this代表它所在方法(函数)所属对象的一个引用
构造函数之间的调用只能通过this语句来完成
构造函数之间进行调用时this语句只能出现在第一行,构造方法要先执行,如果构初始化中还有初始化,那就去执行更细节的初始化
public class Test {
public static void main(String[] args){
Student B=new Student("fd",32);
}
}
class Student{
String name;
int age;
Student(){
System.out.println("无参构造方法");
}
Student(String name){
this();
this.name=name;
System.out.println("fdfd");
}
Student(String name,int age){
this(name);//new Student(name)调用上面的构造方法
this.age=age;
}
}