简单一说,this指当前对象,也可以指当前对象的构造方法
public class Hero {
String name; //姓名
float hp; //血量
float armor; //护甲
int moveSpeed; //移动速度
public Hero(String name,float hp,float armor,int moveSpeed){
this(name,hp);
System.out.println("四个参数的构造方法");
this.armor = armor;
this.moveSpeed = moveSpeed;
}
public Hero(String name,float hp){
System.out.println("两个参数的构造方法");
this.name = name;
this.hp = hp;
}
public static void main(String[] args){
Hero teemo = new Hero("提莫",383,25,300);
System.out.println(teemo.name);
}
}