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 trialRandy Cole
Courses Plus Student 2,494 PointsDon't understand necessity of both Game game = new Game ("treehouse"); and Prompter prompter = new Prompter (game);
Does instantiating prompter not already also instantiate the game object and if so why does it need to be instantiated again by applying Game game = new Game ("treehouse"); ?
2 Answers
Cristiano Monteiro
5,942 PointsI hope this helps: -->Game game = new Game ("treehouse"); <-- The "Game game = new Game " creates an Objekt in the Game class with the name game. In other words. "Game<--is the Datatyp or "Class" , game <-- the name of the Objekt. the ("treehouse") part is there because if u check your Game.java file you should see an Constructor, something like this:
public Game(String answer) {
mAnswer=answer;
mHits ="";
mMisses="";
}
the word ("treehouse") = input String answer in your Constructor. Then its stored in the mAnswer String.
i hope this kinda helped. I know im not the best at explaining.
Cristiano Monteiro
5,942 Pointsnp :)
Randy Cole
Courses Plus Student 2,494 PointsRandy Cole
Courses Plus Student 2,494 PointsOk that makes sense. I think I was ignoring the fact that a constructor was applied and requires an answer to be passed through. Pointing that out helped, Thanks