Say we have a base class Point and a class Circle derives from it.

Say we have the following objects:

Point point1=new Point();
Circle circle1=new Circle();

Then the following is valid:

Point point2=circle1;

point2 should be fully constructed after this statement - so this is fine.

Circle circle2=(Circle) point2

circle2 should be fully constructed after this statement - since point p2 points to a circle, circle2 will point to point2 and be fully defined. So, this is also valid.



But say, now we had:

Circle circle3=(Circle) point1;

We will fail while casting(point1 cannot be casted to a circle - its definition is limited - doesnot include the definition of a circle).

But let us assume the casting succeded.

Even if we were not caught by the casting step, we will fail when we assign circle3 the point1 - this is because we are giving circle3 a simple point and after this stament executes, circle3 is not fully constructed - circle3 consists of [Point+Circle] and only the point part of it is defined by this statement.

So, this may cause a run time error.

Is my analysis correct here?


Thanks
Vikram