User guide

24-64
SystemVerilog Testbench Constructs
Output of program
q = 3
value returned by b1.send() = 8
“this” keyword
The this keyword is used to unambiguously refer to properties or
methods of the current instance. For example, the following
declaration is a common way to write an initialization task:
program P;
class Demo;
integer x;
task new (integer x);
this.x = x;
endtask
endclass
endprogram
The x is now both a property of the class and an argument to the task
new(). In the task new(), an unqualified reference to x will be resolved
by looking at the innermost scope, in this case the subroutine
argument declaration. To access the instance property, we qualify it
with this to refer to the current instance.