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 Creating Classes

I really don't understand the second line!

PezDispenser dispenser = new PezDispenser();

what is this please explain PezDispenser is the another java file? how was this automatically recognized?

dispenser??

new??

PezDispenser()??

should i worry i don't understand this line?

2 Answers

So the format for the second line is (in my own words): <Declare variable type> <name of variable> = <action>

Declaring the variable type is what we've been doing when making a new string. We would start the line with: String nameOfString = xxxx

In this case, the variable type we are using here is "PezDispenser" which we then name "dispenser."

The action is to create the new class, so "new PezDispenser();"

At this point it's calling on the file PezDispenser.java that we made in order to create the new class PezDispenser.

I know I'm answering this months after the question was asked, but maybe it will help anyone else who found this confusing.

in this line i create an object of type PezDispenser. when u create an object u have access to all his methods.