super指代变量,用于在子类中指代父类对象。
三种用法:
访问父类的方法。
调用父类构造方法。
访问父类中的隐藏成员变量。
常用的是访问父类方法,且参数个数类型必须一致
class A{
int x,y;
A(int x,int y){
System.out.println("A");
}
}
class B extends A{
int Z;
B(int x,int y,int z){
Z = z;
super(x,y);
System.out.println("B");
}
}
public class test{
public static void main(String args[]){
B b = new B(1,1,1);
}
}
输出结果:
A
B