class A { public static void main(String[] args)
{ A a = new A();
B b = new B();
A ab = new B();
System.out.format("%d %d %d %d %d %d", a.x, b.x, ab.x, a.y, b.y, ab.y); }
int x = 2;
int y = 3;
A(int x) { this.x = x; }
A() { this(7); } }
class B extends A {
int y = 4;
B() { super(6);
}
Hey all, I was just looking through some examples from my course and came across this problem that stumped me.
I realize that
that this code should print out
"7 6 6 3 4 3"
But why is ab.y equal to 3? Isn't the "real" type of object ab of class B? Which then would lead me to believe that ab.y be 4?