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 trialPassavudh Sabpisal
4,474 PointsWhy did Craig use dispenser.fill(); Where did dispenser come from? What does it mean? STUCK HERE FOR WEEKS.
Why did Craig use dispenser.fill(); Where did dispenser come from? What does it mean? STUCK HERE FOR WEEKS. what does dispenser. mean? why do we use dispenser.? is dispenser. a data type? sorry, I suck at this.
Here is the screenshot URL: https://drive.google.com/file/d/0B5hPm9V6MnngQkh1SHJlWWhQVms/view?usp=sharing
Brandon Khan
21,619 PointsWhat is happening is on line 9 you bring in a the Object PezDispenser ( this is like calling an instance of the class PezDispenser ) in other words this object is giving you access to use the public methods in this class. so PezDispenser dispenser = new PezDispenser(); is making an instance of the class PezDispenser named dispenser. When you want to use a method that is in a class outside of the one your working on you must do this. Then when you have made that object you can call its methods with . so dispenser.fill(); is calling the fill method from the PezDispeser named dispenser you made before.
i hope that helps i know i type like a 4th grader but hay i had issues here too and i just wanted to help best i could.
2 Answers
gmilan
9,287 PointsOn line 8 a new PezDispenser object was created called dispenser. because dispenser was created from PezDispenser class it has access to all the methods in the PezDispenser class. So you can access the fill method by typing dispenser.fill()
Melodie 1
3,931 PointsA dispenser is simply an object used to dispense candies . Craig modelled this real life object in code . Now dispenser.fill() ; means this : dispenser is the name of a reference variable , pointing to an object that has the fill() method , and this fill() method is now being called.
Passavudh Sabpisal
4,474 PointsPassavudh Sabpisal
4,474 Pointswhat does dispenser. mean? why do we use dispenser.? is dispenser. a data type? sorry, I suck at this.