when the Craig type casted the object into a Treet. what will the obj contain, is it the treet or the secondTreet ?.
Hello Good people, when Craig type caste the object into a Treet. what will the obj contain, is it the treet or the secondTreet ?. And my other question is can you typecast Object as a Treet (upward Casting) without first type casting Treet as an Object (down casting).since in java-repl if you create an Object and try to type caste explicitly as a Treet it will through an error(java.lang.ClassCastException: java.lang.Object cannot be cast to com.teamtreehouse.Treet).
thanks for your time.
Tonnie FanadezUX Design Techdegree Graduate 22,770 Points
Just paraphrasing the above comment by sjules.
Whatever is passed in to the compareTo method (likely a Treet) will be an Object. Everything in java is an instance of the the parent Object class, therefore it is safe to just store the argument as an Object. However the parent Object Class doesn't have all of its children methods and properties (with the children methods and properties being the class Treet methods and attributes) So, to ensure that you can access the properties and methods of Treet, you must cast the Object as a Treet