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 Creating the MVP Getting Started

Why did you take constructor method in game.java?

Why did you take constructor method in game.java?

Anders Björkland
Anders Björkland
7,481 Points

The constructor allows for an answer to be set to the private field upon creating a new instance of Game. Since the logic of the game depends on there being an answer to guess at, it is less hassle to set the answer directly upon instantiating (creating) an object of Game than first instantiating an object and then setting the answer of that object. Makes sense?