# Need for the $cast task in System Verilog

**URL:** <https://verificationacademy.com/forums/t/need-for-the-cast-task-in-system-verilog/34640>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Learning-System-Verilog, cast\
**Created:** [July 3, 2018, 11:37am UTC](https://verificationacademy.com/forums/t/need-for-the-cast-task-in-system-verilog/34640 "2018-07-03T11:37:44Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Shri\_Ganesh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/eb9ed0/32.png) [@Shri\_Ganesh](https://verificationacademy.com/forums/u/Shri_Ganesh)\
**Post date:** [July 5, 2018, 6:05am UTC](https://verificationacademy.com/forums/t/need-for-the-cast-task-in-system-verilog/34640/5 "2018-07-05T06:05:17Z")

</div>

_In reply to [javatea](https://verificationacademy.com/forums/t/need-for-the-cast-task-in-system-verilog/34640/4):_

class cast\_parent;  
int a;

task sett (int b);  
a= b;  
$display(“A inside class: %d”, a);  
endtask : sett

task print;  
$display(“A inside class: %d”, a);  
endtask :print

endclass : cast\_parent

class cast\_child extends cast\_parent;

int a = 70000;

task sett (int b);  
a= b;  
$display(“A inside class: %d”, a);  
$display(“B inside class: %d”, b);  
endtask : sett

task print;  
$display(“MGR inside class: %d”, a);  
endtask : print

endclass : cast\_child

module test;  
cast\_parent one;  
cast\_child two;

initial  
begin  
one = new();  
two = new();  
one = two;  
one.sett(1001);  
one.print;  
end

endmodule : test

In the above module, after I have assigned my child handle to parent’s handle, I called the task print via parent’s handle - expecting the printing of the statement - **MGR inside class:** from the child’s class, while the output I got was from the Parent class.

Please clarify.

---

_[View the full topic](https://verificationacademy.com/forums/t/need-for-the-cast-task-in-system-verilog/34640)._
