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.

Java Java Objects (Retired) Creating the MVP Remaining Tries

Eric Park
Eric Park
4,557 Points

Calling 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.

Grigorij Schleifer
Grigorij Schleifer
10,363 Points

Hey Eric,

you are very welcome !

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,363 Points

Hi 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
Eric Park
4,557 Points

Thank you! This really helped! :)