[java] Arrays in classes
How can you put an array as a class member? When I try, the array doesn''t seem to be initialized
public class Classwitharray
{
int a_grid[][][][] = new int[1][1][1][1];
public Classwitharray()
{
a_grid[0][0][0][0] = 1;
}
};
OR
public class Classwitharray
{
int[][][][] a_grid;
public Classwitharray()
{
a_grid = new int[1][1][1][1]
a_grid[0][0][0][0] = 1;
}
};
or maybe something else
please help!!
June 23, 2001 03:23 PM
|
June 24, 2001 01:32 AM
do this:
public class ClassWithArray
{
int[][][][] a_grid = new int[1][1][1][1];
public ClassWithArray()
{
a_grid[0][0][0][0] = 1;
}
}
OR
public class ClassWithArray
{
int[][][][] a_grid;
public ClassWithArray()
{
a_grid = new int[1][1][1][1];
a_grid[0][0][0][0]=1;
}
}
note you don''t need a semicolon after the braces. Basically the key point is that you should declare a variable of type int[][][][], not the messed up C way where it looks like you are declaring an int. Both of the above versions work perfectly and are essentially indistinguisable from each other.
public class ClassWithArray
{
int[][][][] a_grid = new int[1][1][1][1];
public ClassWithArray()
{
a_grid[0][0][0][0] = 1;
}
}
OR
public class ClassWithArray
{
int[][][][] a_grid;
public ClassWithArray()
{
a_grid = new int[1][1][1][1];
a_grid[0][0][0][0]=1;
}
}
note you don''t need a semicolon after the braces. Basically the key point is that you should declare a variable of type int[][][][], not the messed up C way where it looks like you are declaring an int. Both of the above versions work perfectly and are essentially indistinguisable from each other.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement