Confusion over casting of classes

In reply to dave_59:

The assignment from
child_handle
to
parent_handle
is always allowed, but an assignment the reverse direction can only be checked at runtime using $cast. Suppose you had:

initial begin
        parent_handle = new();
        child_handle = parent_handle; // not legal
        $display("I am child with member of value %d",child_handle.foo_mem);
end

The reference to
child_handle.foo_mem
is only valid if
child_handle
contains a handle to a
child_
class type.

…[/code][/quote]

I don’t know if the above statement is correct.
For example, I am able to properly compile the following code …

module casting;
class BaseC;
endclass: BaseC

class DerivedC extends BaseC;
  int x;
endclass : DerivedC

BaseC    P1 ;
DerivedC P2 = new;

initial begin
  P1 = P2; 
end

endmodule

In the above code, derived class object is assigned to base class handle.