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 trial

Java Java Objects (Retired) Meet Objects Creating Classes

Dwayne Bunkley
Dwayne Bunkley
1,259 Points

I don't understand why the variable type is PezDispenser. Can someone explain that further?

In the example file when he used the PezDispenser class, he referred to it as the variable type to. Just trying to understand why that is a variable type.

2 Answers

Remember Dwayne when you are working with variables in Java you are either working with primitive data types (like int, double) or Objects (like String, Employee, PezDispenser) 'Primitives' can only do 1 thing - store a piece of data (like a number). They are always lowercase 'Objects' can do many things (defined as methods) and contain lots of properties (often defined as other primitives or Strings). They are always uppercase (like your PezDispenser)

Dwayne Bunkley
Dwayne Bunkley
1,259 Points

Thanks John. I forgot that Objects were also considered data types not just int, double etc. That's probably another reason I wasn't completely getting it.

Rebecca Rich
PLUS
Rebecca Rich
Courses Plus Student 8,592 Points

Later on when you create PezDispenser objects (instances of the PezDispenser class), you could create a variable to represent the PezDispenser object:

PezDispenser pd = new PezDispenser(...);

In this case, pd is a variable (or object) of type PezDispenser.

Dwayne Bunkley
Dwayne Bunkley
1,259 Points

Thank you Rebecca!!!! I finally understand it now. Objects, classes, and methods were always such an abstract concept to wrap my head around and I am beginning to really understand it now. Thank you very much!