super關鍵字的用法有三種:
- 1、在子類的成員方法中,通路父類的成員變量。
- 2、在子類的成員方法中,通路父類的成員方法。
- 3、在子類的構造方法中,通路父類的構造方法。
public class Fu {
int num = 10;
public void method() {
System.out.println("父類方法");
}
}
public class Zi extends Fu{
int num = 20;
public Zi() {
super();
}
public void methodZi() {
System.out.println(super.num);//父類中的num
}
public void method() {
super.method();//通路父類中的method方法
System.out.println("子類方法");
}
}