Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTony Brackins
28,766 PointsWhy are we making a "private Game mGame" in the prompter class, then making a constructor "Prompter(Game game)" ?
Why are we making a "private Game mGame" in the prompter class, then making a constructor "Prompter(Game game)" ? Don't we already have a constructor for Game in the Game class? Shouldn't we just say "Game game = new Game"?
Thanks,
Tony
1 Answer
Steve Hunter
57,712 PointsThe Prompter
constructor is for the Prompter
class and it takes a Game
object to instantiate the Prompter
object.
The Game
constructor is called when the mGame
variable is initialised, I presume.
So, within the Prompter
initialiser, it'll assign the game
instance passed in to it to initialise mGame
with game
.
I hope that makes sense! I've not done that course so have no working knowledge of the code but do understand why that might be confusing. Think about instances, multiple versions, rather than just one use - the whole class object thing makes more sense when you "think big".
Shout if you need more - or give me a shout on Twitter; @OnlySteveH
Steve.
Tony Brackins
28,766 PointsTony Brackins
28,766 PointsThanks Steve! I think I get it.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsCool! Keep at it; doing it every day makes it better.
Same with coding.
Steve.
Exits stage left followed by bear