User guide

24-43
SystemVerilog Testbench Constructs
handle_name = new([arguments]);
Arguments are optional.
Below is an example of a user-defined constructor:
program P;
class B; //declare class
integer command;
function new(integer inCommand = 1);
command = inCommand;
$display("command = %d", command);
endfunction
endclass
endprogram
When called, new() will print the value passed to it as the value of
command.
When a class property has been initialized in its declaration, the
user-defined new() constructor can be used to override the initialized
value. The following example is a variant of the first example in this
section.
program P;
class A;
int q = 3; //q is initialized to 3
function new();
q = 4; //constructor overrides & assigns 4
endfunction
endclass
A a1;
initial
begin
a1 = new;
$display("The value of q is %0d.", a1.q);
end
endprogram