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 (Retired) Harnessing the Power of Objects Helper Methods and Conditionals

Constructor Parameters

Why are we able to set mBarsCount to zero inside the constructor class when we've set its parameters to take Strings, not integers?

1 Answer

Hi John,

The constructor is designed to require a value be provided every time a class is instantiated. In this case, there shouldn't be a default color for a go kart, so you have to tell it which color you want. Bars starting at zero is a property of the instantiated object, but it's not one that's required to define to create a go kart - the instance created will default to no bars.

Basically, the parameters are what are required for that constructor. If you wanted to make a second constructor which took both a string to define the color and an int for the battery bars, you could, then you could either call goKart("blue"); or goKart("blue", 8); if you wanted it to start off with a charged battery.

Hope that helps!

Wow, that was a crazy good answer. Thanks!!!