62,615
社区成员
发帖
与我相关
我的任务
分享
class Father {
private int fage;
public int getFage() {
return fage;
}
public void setFage(int fage) {
this.fage = fage;
}
int fweight;
protected String fgender;
public int fheight;
public Father(int age, int weight, String gender, int height) {
this.fage = age;
this.fweight = weight;
this.fgender = gender;
this.fheight = height;
}
public Father() {}
}
public class FatherAndSon extends Father{
private int sage;
int sweight;
protected String sgender;
public int sheight;
public FatherAndSon(int age, int weight, String gender, int height) {
super(55, 130, "male", 160);
this.sage = age;
this.sweight = weight;
this.sgender = gender;
this.sheight = height;
}
public static void main(String[] args) {
Father f = new Father(50, 130, "male", 160);
FatherAndSon s = new FatherAndSon(25, 130, "male", 170);
//System.out.println(f.fage); 为什么父类对象f在这里不能访问自己的private属性
}
}