In the code below what triggers my curiosity and my understanding is that the line tagged with Tag: produces q.y = 7 ?
Anyone can direct my research on this ?
<pre>
class Shape {
int x=7, y=7;
int getY() {
System.out.println("Shape " + y);
return y;
}
}
class SubShape extends Shape {
int x=5, y=5;
int getY() {
System.out.println("SubShape " + y);
return y;
}
}
class CastObj extends Object {
public static void main(String args[]) {
Shape p = new Shape();
System.out.println("p.y = " + p.y + " p.getY() = "+ p.getY());
Shape q = new SubShape();
System.out.println("q.y = " + q.y + " q.getY() = "+ q.getY());
Tag:System.out.println("p.y = " + p.y + " q.y = "+ q.y);
System.out.println("p.getY() =" + p.getY() + " q.gety() " + q.getY());
}
}
// Result printed out
//
// Shape 7
// p.y = 7 p.getY() = 7
// SubShape 5
// q.y = 7 q.getY() = 5
// p.y = 7 q.y = 7
// Shape 7
// SubShape 5
// p.getY() =7 q.gety() 5
//
</pre>
[This message has been edited by Vroummmmm (edited June 12, 2000).]