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 trialEric Park
4,557 PointsCalling a method
Hi, I was wondering why we have to type in Prompter.play() instead of mGame.play(). I am confused because play is not a static method, and yet we call it using the Prompter class.
1 Answer
Grigorij Schleifer
10,365 PointsHi Eric,
we call promter.play(); (prompter is lowercased).
Inside our Hangman class we create an instance of the Prompter class and call it "prompter". In other words "prompter" is the object of the Promter class. We need this instantiation for accessing the methods of the Prompter class like play() through the dot Operator (.).
Like this:
prompter.play();
Would be play() a static method, you could use it without creating a instance/object of the Prompter class.
I hope I could clear things a little bit up....
Grigorij
Eric Park
4,557 PointsThank you! This really helped! :)
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey Eric,
you are very welcome !