User guide
24-56
SystemVerilog Testbench Constructs
Base: p=2
Extended: q=3
In the above example, the method, display() defined in Extended
calls display(), which is defined in the super class, Base. This is
achieved by using the super keyword.
The property may be a member declared a level up or a member
inherited by the class one level up. Only one level of super is
supported.
When using the super keyword within the constructor, new, it must
be the first statement executed in the constructor. This is to ensure
the initialization of the superclass prior to the initialization of the
subclass.
Casting
$cast enables you to assign values to variables that might not
ordinarily be valid because of differing data type.
The following example involves casting a base class handle (“b2”),
which actually holds an extended class-handle (“e1”), at runtime back
into an extended class-handle (“e2”).
program sample;
class Base;
integer p;
virtual task display();
$write("\nBase: p=%0d\n", p);
endtask
endclass
class Extended extends Base;