Originally posted by Ismael Upright:
Here's a bunch of definitions and reference declarations from jqplus6:
1. Let's say that we do the following:
o3 = o1;
It won't compile because superclass reference cannot be assigned to subclass reference without explicit cast. So I did the cast:
o3 = (C3)o1;
And Eclipse wrote:
Syntax error on token "o3", VariableDeclaratorId expected after this token.
Why?
becuase you cannot downcast an object , you can only upcast
it means you can do
Parent obj = new ChildBoj()
or
Parent obj = (Parent) new ChildObj();
but not
Child obj = new Parentobj()
or Child obj = (ChildObj) new ParentObj()
2. There is another assignment:
o3 = o2;
It also seems to be not correct. Why? Both o2 and o3 IS A interface I2 so...?
in this case 03 is an object of type C3 and o2 of C2 and not of type interface I2