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!
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
Caspar Claessen9,060 Points
Dear fellow students,
I have the following question Why is the object (is it called an obejct?) where we need to pass a name to called 'Pezdispenser dispenser' and not just Pezdispenser
Anders Björkland7,481 Points
Think of the class Pezdispenser (where the code is), as a blueprint of a house. It is not able to house a family while it is just a blueprint, so you get a construction company to build the house according to the blueprint. The constructed house is now an object, and can do what it is supposed to do. A family can now move in there. Then another family wants to move in to a house. They can't move in to the already created one, a family is already living there! So they call the construction company and builds a new house.
This is also what's going on with the Pezdispenser. It's a class you have to create different pezdispensers, because maybe just one isn't enough. When you type Pezdispenser dispenser, you are giving it a reference name, a way to know which of the pezdispensers you are actually talking about. For instance, one may be called casparsDispenser, and another anderssDispenser.
To break it down. This is how you could construct a Pezdispenser:
Pezdispenser dispenser = new Pezdispenser("Yoda");
_____^_________ ^ _____ ^ _________ ^ __________________
(type/class) ___ (name) (new) (the types construction company, and your personal touch (Yoda))
You can't call it simply Pezdispenser because there may be a multitude of different objects of that class. You have an object already and you named it dispenser. There are cases where there are not expected to be a multitude of objects of a class (this is also called instances of that class), so in those cases you dont have to write something like Pezdispenser dispenser because you don't need to distinguish it from other objects.
Hm, did any of that make sense? Good luck!
Rafał Sobczyk3,274 Points
Just as you write "String name" instead of just "String", or "int age" instead of just "int", you need to name your new Pezdispenser object.