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.
Steve HunterTreehouse Moderator 54,649 Points
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,