Let’s say for instance that we have a class Board with many fields (i.e. a rather complex class). We instantiate a Board like so:
Board b = new Board();
Note that for the sake of this example, I am not entering any parameters into the constructor, though in a real example, those may be necessary. If we were to then instantiate a new instance of Board and set it equal to be like so:
Board c = b;
This would not actually create a new board. From what I know, c and b now point to the same area of memory, the same Board object. So, if I were to change something about b, say be incrementing an integer field, like so:
b.count++;//Assume count is an integer field in the Board class.
The value c.count should be incremented as well. However, when I do this myself, it doesn’t work. b.count is incremented, yet c.count is not.
Can anyone explain to me why this happens? This effect is something I want to have happen, thus any advice on how to implement this would be very helpful (General examples are fine).
Wrong again: