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.
Where did the console find Yoda???
I can't understand, how did the console write that the character is Yoda, if it wasn't in a code.
In main, you did 2 things:
first, you requested an object of type PezDispenser . This is like going to a store and buy an Apple. So now you have an Apple in hand and you called it myApple. Instead of Apple think (PezDispenser ) . In this case, you have a specific PezDispenser in hand, and you are called it dispenser. PezDispenser dispenser = new PezDispenser();
The apple has a built in attribute .... Color. If it is a red apple, then Color = Red. Now think of your dispenser; dispenser has a character .... it called mCharacterName.
The way you refer to apple color is: tell me what is ........> apple.color
here you are saying tell me what is ........> dispenser.mCharacterName
System.out.printf("the dispenser character is %s\n", dispenser.mCharacterName);
since the dispenser object has an attribute mCharacterName = "Yoda"
then dispenser.mCharacterName will return "Yoda"
hope this helps.