package one ;
class one {
public static void main (String args[] ){
dw g = new dw(3);
dog f = new dog(4);
g.pr();
f.print();
g.pr();
}
}
class dw {
int a;
public dw (int a){
this.a=a;
System.out.println("构造器"+this.a);
}
public void pr(){
System.out.println("父类a:"+a);
}
}
class dog extends dw {
int a;
public dog(int a){
super(a);
this.a=a;
}
public void print(){
System.out.println("super a :"+super.a);
System.out.println("子类a:"+this.a);
super.pr();
}
}
输出结果是
构造器3
构造器4
父类a:3
super a :4
子类a:4
父类a:4
父类a:3
super不是指向父类嘛?还是子类调用构造器的原因使父类值临时改变了?
刚学java 望大佬细心解答一下 感谢