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.
Siu KWAN YuenCourses Plus Student 2,898 Points
How 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?