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 Meet Objects Constructors

Brendan Passey
Brendan Passey
999 Points

At what point to we ask users to pass in a string to our constructor?

He says at about 3.48 that the code public PezDispenser(String characterName) { this.characterName = characterName; } is asking the user to pass in a string arguement but i don't see how. We aren't using Console.readline or any similar method to ask for user input so what does he mean? Is it just seudo code? I've also run the code and it never prompt for input...... please explain?

1 Answer

Andy Stevens
.a{fill-rule:evenodd;}techdegree seal-36
Andy Stevens
Front End Web Development Techdegree Graduate 20,417 Points

I see the confusion, the name is passed in as an argument when creating the object PezDizpenser i.e. PezDizpenser dispenser = new PezDizpenser(โ€œYodaโ€);

I guess Craig is referring to himself as the user.