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!

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 (Retired) Creating the MVP Prompting for Guesses

Jagmeet Singh
Jagmeet Singh
2,449 Points

what is the method public prompter(Game game){ mGame = game; } doing?

what is this method actually doing?

1 Answer

Hi Jagmeet,

The Prompter method inside the Prompter class is an example of a constructor.

You use constructors to build the instance of the class when you create one. In this case, since the Prompter class instances hold a member variable that is a Game object, the constructor is receiving an instance of Game as a parameter. The parameter for the constructor Game game tells you that a Game object called game has been passed in. That instance is then assigned to the member variable of the Prompter instance, called mGame.

So, you create an instance of the Prompter class by sending a Game object to the Prompter() constructor which is then stored in the member variable mGame.

I hope that helps!


Jagmeet Singh
Jagmeet Singh
2,449 Points

Thank you Steve! Appreciate!

No problem! :-)