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

Aditya Sheode
Aditya Sheode
1,291 Points

PezDispenser dispenser = new PezDispenser();

I have a few questions regarding the statement above

  1. He referred to PezDispenser as a data type why? 2.Why PezDispenser();? 3.How does he exactly point the example file to the Pezdispenser?

2 Answers

  1. PezDispenser is the data type because it only allows information of the type PezDispenser. Or, put another way, if you use a primitive data type int, you can only use integers and nothing else - otherwise you'll get an error. Same with the class you've created.

  2. The PezDispenser() points to the constructor in the Pez Dispenser class. A constructor is similar to a method in how it's called. Later on, you will learn about the arguments you can pass into the ().

  3. He imported the class at the top of the page.