java - How do I access a certain element of an object if you are in another class? -
I have a class that includes a 2D four [] [] array that connects four boards. Each of the four elements has an 'x' or 'o'
Now I am trying to get the contents of this board, I am in, for example,
public class connect 4 {private class] [] board; } Public Nucleus {Private Connect 4 Board; Board = new connect 4 (size x, size); Board ..... and lieutenant; - How do I use Connect 4 objects of the Caribbean if I am in the Newcastle? }
thanks
you board
Because you have made it personal
if you want to make it publicly accessible, then you have two options.
Option 1 - Accelerator methods
Keep the board
field private
and your Connect4 makes it accessible through an accessor (aka setter) method within the class. Public Zero Setboard SlotTenaxen Expansion {If (board [row] [cola] == 'A') throw new slotconconception ("one player has already kept one piece.") ; Board [row] [color] = player; }
Note that if I do not know about the exceptions yet, you can learn about them. You can find more information about the accelerator / setter / mutator methods.
Option 2 - Public Field
If you do not care who touches your board, you can simply create the board yourself Any method will work, but the first method allows you to have the responsibility of the A complex game board should probably never be public, because it can be for players who make a move in the same slot. Some netrologists argue that using a public modifier in front of an area is not a good idea. Should you decide to ignore their warning:
Public four [] [] Board;
board
class to maintain your consistent status, which is more acceptable The method is. / P>
Comments
Post a Comment