class A;
int data;
function new(input int x);
this.data = x;
endfunction
endclass
class B extends A;
function new(input int y, input int z);
super.new(z);
super.data = y;
//this.data = 3;
endfunction
endclass
module top;
initial begin
A a;
B b;
a = new(4);
b = new(7,9);
#5 $display("Data in A is %d", a.data);
#5 $display("Data in B is %d", b.data);
end
endmodule
First A constructor sets A data to be 4. Very fine.
Next super.new() in B constructor sets A data to be 9. Shouldnt it get overwritten to 9 from 4?
Now super.data = 7 should again overwrite 9 to 7. Hence a.data shouldnt it be 7? (4->9->7)
Also why is B’s data getting 7? Im calling super.data, not this.data.