I having a class named Shape which has two subclasses Shape1 and Shape2. In the Shape class I have variables Xpos and Xpos and methods namely:
public int getXpos(){
return Xpos;
}
public void setXpos(int x){
this.x = x;
}
// Same thing for y
Now let’s just say in the class Shape, x = 10. Now when I inherit it:
public class Shape1{
Shape1(){
xPos = 100;
// ...
}
}
and:
public class Shape2{
Shape2(){
xPos = 200;
// ...
}
}
But when I do Shape1.getX() in another program, I get 10 as a result. Can someone tell me why I’m not getting 100? Is the problem with the ‘this’ keyword?
xPos cannot be static. If it is static the same number will appear twice. (the original shape)