I'm learning Java using Sams Teach Yourself Java in 21 days (btw this is taking me much longer than 21 days). In chapter 5, the final exercise asks me to create a class FourDPoint which is a subclass of Point. I did this, but had an interesting result. The first time I did the exercise this was my code:
import java.awt.Point;
class FourDPoint extends Point {
int x;
int y;
int z;
int t;
FourDPoint(int x, int y, int z, int t){
super(x, y);
this.z = z;
this.t = t;
}
public static void main(String[] arguments){
FourDPoint fp = new FourDPoint(5, 5, 10, 10);
System.out.println("x is " + fp.x);
System.out.println("y is " + fp.y);
System.out.println("z is " + fp.z);
System.out.println("t is " + fp.t);
}
}
The result: x is 0, y is 0, z is 10, y is 10.
I changed my code by eliminating the intitilized x and y, which gave me the correct answer. My question: why did I get x is 0 and y is 0? Do the intitiaized x and y take precedence over the super(x, y)?