I’m trying to understand super.new() behavior when its called in the derived class… I was expecting the super.new(value) call in the child class to assign 77 to its variable “value” . Or if it got assigned to base class’s value wouldn’t that still be available to the child class because of inheritence
class BaseClass;
int value;
function new (int value);
$display("function new from BaseClass");
this.value = value;
endfunction
function void display();
$display("display function from BaseClass = %d", value);
endfunction
endclass
class SubClass extends BaseClass;
int value;
function new (int value);
super.new(value);
//this.value = value;
endfunction
function void display();
$display("display function from ChildClass = %d", value);
endfunction
endclass
module tb;
BaseClass bc;
SubClass sc;
initial begin
bc = new (44);
sc = new (77);
bc.display();
sc.display();
end
endmodule
Results:
function new from BaseClass
function new from BaseClass
display function from BaseClass = 44
display function from ChildClass = 0 → Why is this 0 instead of 77?