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 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.