User guide

24-57
SystemVerilog Testbench Constructs
integer q;
virtual task display();
super.display();
$write("Extended: q=%0d\n", q);
endtask
endclass
Base b1 = new(), b2;
Extended e1 = new(), e2;
initial begin
b1.p = 1;
$write("Shows the original base property p\n");
b1.display(); // Just shows base property
e1.p = 2;
e1.q = 3;
$write("Shows the new value of the base property, p,
and value of the extended property, q\n");
e1.display(); // Shows base and extended properties
// Have the base handle b2 point to the extended object
b2 = e1;
$write("The base handle b2 is pointing to the
Extended object\n");
b2.display(); // Calls Extended.display
// Try to assign extended object in b2 to extended handle e2
$write("Using $cast to assign b2 to e2\n");
if ($cast(e2, b2))
e2.display(); // Calls Extended.display
else
$write("cast_assign of b2 to e2
failed\n");
end
endprogram
Output of the above program is:
Shows the base property p, which is originally 1
Base: p=1