0

Can I have one reference of an object amongst multiple classes in Java?

I'm making a text adventure, with all the objects and rooms as separate classes, and I made a boolean variable in the player class for each room to decide if the player is in that room or not. I try calling and changing that variable in other classes, but it doesn't change. So I'm just wondering if it's possible to make only one reference of the player object that can be called and changed in the room classes. Any help is greatly appreciated. Thanks!

3rd Dec 2017, 1:31 AM
Justin Bornais
Justin Bornais - avatar
1 Answer
+ 1
I don't see any problem with that, if you pass the reference around to all the classes. Hard to say anything else, since you haven't provided the source code.
3rd Dec 2017, 1:39 AM
eRosz
eRosz - avatar