I made an object called one using the Shape class, and I called the instance variable x1 for 'one', and set it to int x by doing int x = one.x1; and it works fine. But when I tried to do that in a different class, it doesn't work at all. When I tried to do that in a different class an error message shows up that said "one cannot be resolve to a variable." If anyone know what's wrong, and how to fix this, please let me know. Thank you.
package events;
public class Shape {
int x1;
int x2;
int y1;
int y2;
int width;
int height;
Shape(int x1, int y1, int width, int height) {
this.x1 = x1;
this.y1 = y1;
this.width = width;
this.height = height;
this.x2 = x1 + width;
this.y2 = y1 + height;
}
public static void main(String[] args){
Shape one = new Shape(4,4,4,4);
int x = one.x1;
}
}
The codes that doesn't work:
package events;
public class test {
public static void main(String[] args){
int x = one.x1;
}
}
oneis defined insidemain()method and is not accessible nor visible anywhere outside it.onedeclared?