本帖最后由 li6232876 于 2016-3-24 10:28 编辑
class Demo_Father {
public static void main(String[] args) {
Son s = new Son (4);
System.out.println(s.getX());
}
}
class Father {
private int x ; //定义私有x
public Father(int x) {
this.x = x;
System.out.println("父类的有参构造,x="+x);
}
public void setX(int x) { //设置x
this.x = x;
}
public int getX() { //获取x
return x;
}
}
class Son extends Father {
private int x ;
public Son(int x) {
super(x);
System.out.println("子类的有参构造,x="+x);
}
}
结果:
父类的有参构造,x=4
子类的有参构造,x=4
4 (???最后这个4是怎么输出的???)
|
|