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 trialmartinpatino2
4,741 PointsConstructor question: public Prompter (Game game) { mGame = game; }
I am unsure what the variable "Game" stands for in the following constructor.
Is it reaching out to a different class?
public Prompter (Game game) { mGame = game;
1 Answer
Allan Clark
10,810 PointsThe program starts in the Hangman.java with this:
public static void main(String[] args) {
// Enter amazing code here:
Game game = new Game("treehouse");
Prompter prompter = new Prompter(game);
boolean isHit = prompter.promptForGuess();
if(isHit){
System.out.println("We got a hit");
} else{
System.out.println("Whoops missed");
}
}
This creates a new instance of the Game class (giving it the word we want the user to guess), then passes that Game instance to the Prompter constructor. The 'game' variable inside that constructor is holding the Game instance it was passed.
Hope this helps
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsGreat answer !!!!