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 trial

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?