Hi i try to make program who when will be compiled print X and Id arrays but i have a problem when i try add static int. I made this like on tutorial but it can't compile. Do you have any suggest?
class SetCord
{
double x;
double y;
private int Id;
private static int NextId;
public SetCord(double a, double b)
{
x=a;
y=b;
}
public double getX()
{
return x;
Id=NextId;
NextId++;
}
public double getY()
{
return y;
Id=NextId;
NextId++;
}
public int getId()
{
return Id;
}
}
class Test
{
public static void main(String args[])
{
SetCord[] teste = new SetCord[3];
teste[0] = new SetCord(3, 5);
teste[1] = new SetCord(5, 5);
teste[2] = new SetCord(1, 2);
for(SetCord x:teste)
{
System.out.println("give x" + x.getX());
System.out.println("give id" + x.getId());
}
}
static
{
NextId=1;
}
}
Thanks!