Hi,
For the following code, In class B, method set_prop why is this.count is referring to the property of class A where as it should be referring to the B’s count variable. It is slightly confusing. Since we are calling using b’s handle, my expectation is that, “this” should point to the B’s scope.
class A;
int count=10;
virtual function set_prop (int x=this.count);
count=x;
$display("In class A -- count is set to %d",count);
endfunction
endclass
class B extends A;
int count=20;
function set_prop (int x=this.count);
count=x;
$display("In class B -- count is set to %d",count);
endfunction
endclass
module top;
initial begin
A a;
B b=new();
a=b;
a.set_prop();
b.set_prop();
a.set_prop(50);
b.set_prop(60);
end
endmodule
Output:
In class B -- count is set to 10
In class B -- count is set to 10
In class B -- count is set to 50
In class B -- count is set to 60