In reply to dave_59:
Please refer the below code
class A;
rand bit[3:0] j;
virtual function my_function();
this.randomize();
endfunction
virtual function build();
my_function();
endfunction
endclass
class B extends A;
rand bit [7:0] x;
virtual function build();
super.build();
endfunction
endclass
module top();
B b;
initial begin
b=new();
b.build();
$display(" b %p",b);
end
endmodule
Output
vsim -voptargs=+acc=npr
run -all
b '{j:9, x:35}
exit
In this code,though we are calling only the build function which is internally calling this.randomize(); of class A,still, the variable of class B is getting randomized. My understanding is “this” should have a scope of only class A and should not have access to class B variables.