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 Data Structures Getting There Packages

nikhil davasam
nikhil davasam
2,182 Points

Treet treet = new Treet

what does this signify ? meaning of[ this line of code

3 Answers

Hi Nikhil,

You're creating a new instance of the Treet class. It is called treet. To the left of the equals sign, you create a Treet sized hole in memory and label it treet so you can access it later. You then assign into that hole an actual instance of a Treet by using the equals sign, to the right of it create a Treet by using the keyword new then calling the constructor called Treet(). That makes an object/instance of the class.

So, you make a treet sized hole labelled treet, create an actual Treet instance and put that instance in the hole!

Make sense?

Steve.

nikhil davasam
nikhil davasam
2,182 Points

yesigetit iamnotabletousespacebecozmykeyboardisfucked thankyousomuch

nikhil davasam
nikhil davasam
2,182 Points

very well explained steve! i will tell what i understood there will be a hole with one name . with the same type of hole you create, another hole with reference to that hole and that hole follows the methord of the first hole that is created. am i right?

Hi Nikhil,

Sorry for the slow response, I was out with friends for a beer.

The way I visualise this is that I create a memory hole with a label by declaring the variable name:

Treet treet;

That creates a hole in memory ready to be filled with an instance of a Treet. The hole has a label so we can reference it.

We next need to create an instance of the Treet class which we do by calling the constructor of the class. We assign that instance into the hole, filling it, and allowing us to access that instance with the label we created above.

Treet treet = new Treet();

So there's one hole and one hole-sized instance. We put the instance in the hole and access it using the label we crested for the hole.

I hope that helps. Do you understand constructors, instances, objects etc? I did a post about that somewhere. I'll post a link if it would help.

Steve.