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!
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
Nayoon kim3,098 Points
Question about 'instance'
Card c = new Card();
- I know that this sentence creates an instance (which is an object) of Card class
- and that instance is stored to c
- Card(); is the constructor.
But I'm confused which part of the sentence is the instance of Card class.. is it
Card at the head bit? or the whole thing is the ... instance of Card class.
I feel like there are a lot to cover in java object but here, the course skims through all the important details.
Calling the constructor together with the
new keyword returns an instance of
Card. This is then stored in
c. The first
Card, at the beginning of the expression, is used to allocate enough memory to the variable
c to hold the instance of
So, to the left of the equals sign, you create a
Card sized hole in memory. You then create an instance/object of
Card by calling the constructor with the
new keyword. This returns the object which is assigned into
c using the
I hope that helps,