How do you pass two class objects as parameters?
Also, if the object sq can be used to call getters, then what is the purpose of the move object?
I would like an example with an explanation of how to do this in java since I don't understand this.
Here is this example of a method with two objects as parameters.
private void move(Board sq, Board move){
...
space[sq.getX()][sq.getY()];
}
Passing two class objects as arguments to a function is just like passing any other arguments. There is hardly any difference.
Below is the syntax to pass two class objects to a function:
private void function_name(Class1 object1, Class2 object2) {
// function body
}
Note that Class1 and Class2 are placeholders for actual class name.
Now, in your case, Board sq and Board move are the two function arguments. The object sq could be used to call the getters and set the final state of the board in the object move by calling its setters.
Get Answers For Free
Most questions answered within 1 hours.