I've got two classes, one called "Territory" which constructs an object with the following variables: "posX" and "posY", like this:
public Territory(int column, int row)
{
posX = column;
posY = row;
}
Then in another class, "World" I do the following:
Territory territory1 = new Territory(0, 0);
But then when I try to reference some of the variables from that object, i.e. like this:
System.out.println("Coordinates: " + territory1.posX);
I get the error:
cannot find symbol - variable territory1
Any help?
EDIT:
Here are the full classes:
Territory:
public class Territory
{
public int posX;
public int posY;
public int armies;
public String owner;
public Territory(int column, int row)
{
posX = column;
posY = row;
armies = 0;
owner = null;
}
}
World:
public class World
{
public World()
{
Player player1 = new Player();
Player player2 = new Player();
Territory territory1 = new Territory(0, 0);
Territory territory2 = new Territory(1, 0);
Territory territory3 = new Territory(0, 1);
Territory territory4 = new Territory(1, 1);
}
public java.lang.String toString()
{
System.out.println(territory1.getposX);
}
}
territory1though, based on the error, and not with the access modifiers of its fields.