I can give you a example this may be very helpful to you.
class Base;
endclass
class child extends base ;
task display ();
$display(" This is true ");
endtask
endclass
module main ;
child my_child;
base my_base;
initial
begin
my_child = new();
my_base = my_child;
my_child.display();
my_base.display();
end
endmodule
RESULT :
The above code result in the ERROR.
Now i doing some modification :
class base ;
endclass
class child extends base ;
task display ();
$display(" This is again true ");
endtask
endclass
module main ;
child my_child;
base my_base;
initial
begin
my_child = new();
my_base = my_child;
type_conv(my_base);
end
endmodule
task type_conv(base my_base);
child ch;
$cast(ch,my_base);
ch.display();
endtask
RESULT :
This is again true
To access the variables and methods which are only in the subclass and not in the parent class, revert back the object to the subclass handle.AS the methods which are added in the subclasses which are not in the parent class can’t be accessed using the parent class handle.