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 trial

Java Java Objects Creating the MVP Prompting for Guesses

private Game game;

How come in Prompter.java, instead of private String game is use, private Game game was used? Why?

Thanks!

5 Answers

game is not a string, it is an object. Prompter is not taking strings, it is taking instanciated objects.

Hi Passavudh

A new game object has already been instantiated in hangman.java. In hangman.java that game object is being passed into the promoter constructor. The private Game game in prompter is just a private member variable that the passed in game object gets assigned to to be used by the promoter methods

Fahad Mutair
Fahad Mutair
10,359 Points

hi Lawrence Babay ,

private Game game it will make object from Game.java class

private String game it will make String variable

why don't we use (Game game = new Game()) for instatiating the object, I'm kind of confused pls help. What is the different between Game game = new Game() and private Game game

Thank you all!

why don't we use (Game game = new Game()) for instatiating the object, I'm kind of confused pls help. What is the different between Game game = new Game() and private Game game