java 的this和super
- this.当前类的的变量名=要使用的参数
public class Person(){
String name;
public Person(String name){
this.name = name;
// ↑ ↑
//这个类的 传递进来的参数
}
}
============================
- super用于访问父类中的变量和方法
- 私有的不能被继承
public class Student extends Person{
super.print();//调用父类的方法
system.out.println(super.name);//调用父类的变量
public class Person{//父类
String name=“clx”;
public void print(){
system.out.println(“clx”);
}
}
}