Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Jagmeet Singh
2,449 Pointswhat is the method public prompter(Game game){ mGame = game; } doing?
what is this method actually doing?
1 Answer

Steve Hunter
57,682 PointsHi 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!
Steve.
Jagmeet Singh
2,449 PointsJagmeet Singh
2,449 PointsThank you Steve! Appreciate!
Steve Hunter
57,682 PointsSteve Hunter
57,682 PointsNo problem! :-)