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 trialSiu KWAN Yuen
Courses Plus Student 2,898 PointsHow does the reference of an original instance different from that of its up/down casted instance?
Treet treet = new Treet("Sean", "Hello", new Date())
Object obj = treet;
Treet another = (Treet) obj;
In the above code, We have an obj of class Object; however, the member variables of obj are all included in the instance, treet, and so, there is nothing new.
Does our computer store obj in a new memory? or do they (obj and treet) are referencing the same thing?
Btw, I have an assumption that needs to be confirmed. When you coercion the type of an instance, the converted instance only keeps the member variables of the new blueprint, meaning that when you upcast, it keeps all member variables of its super class, and when you downcast, it keeps all original member variables and set all new variables to the default value. is that true?