java——继承下的super
作者:互联网
package Project1;
import java.util.*;
class father{
private int num=0;
public void setNun(int num) {
this.num = num;
}
public int getNum(){
return num;
}
}
class son extends father{
public int getNum(){
return super.getNum();//此处必须加super,因为father的num是private的要访问只能用方法
//而此处的方法也是getNum优先调用的是子类重载的方法不用super是用的father的
//不然就是无限循环
}
}
public class Main{
public static void main(String[] args){
var a=new son();
System.out.println(a.getNum());
}
}
标签:java,继承,father,int,getNum,num,super,public 来源: https://www.cnblogs.com/shuangquantang/p/15762033.html