| Author |
array
|
basia fish
Greenhorn
Joined: Aug 04, 2003
Posts: 17
|
|
hi 1. i have public static final int BOX = 0; public static final int CIRCLE = 1; if i want to put the elements into an array do the array have to be public static final or it can be private and then i just write set and get methods to access and update array 2. is it how I use get and set methods? private StringBuffer m[][]; // set methods public void setm(int a[][]) { m = a; } public int[][] getm() { return m; } any help appreciated thanks barbara
|
 |
Dipen Javia
Greenhorn
Joined: Jun 12, 2004
Posts: 5
|
|
Hey barbara, You have your array initialized as StringBuffer, but you have data type as 'int' in setm() and getm(). I recommend that you change all 'int' into 'StringBuffer'. Plus, (m == a) will set the value of m, which is the memory location of the array, into the variable 'a'. You can have your arrays private. Private can be accessed within the class. You might want to consider using loops to go through an array and access/modify it. Here is an example: In the example above, setM() will set the value "myValue" in the array, and the getM() will print "myValue" 10 times. [ June 15, 2004: Message edited by: Dipen Javia ]
|
Dipen Javia.
|
 |
Ben Buchli
Ranch Hand
Joined: Mar 26, 2004
Posts: 83
|
|
barbara, when you declare your ints as final, they are final, or in other words, they are accessible directly but immutable. So it doesnt matter whether your array is public or private. However, it depends on the use of your class whether you want to have the array private (need accessor methods) or public (dont need accessor methods). One more thing, the way you pass your array, you only pass its reference to the method, so you want to create a new array inside the setm() and then copy the a[][] into that new array. hope that helps. ben
|
 |
 |
|
|
subject: array
|
|
|