class base;
int N = 3;
function int get_N();
return N;
endfunction
endclass
class ext extends base;
int N = 4;
function int get_N();
return N;
endfunction
function int get_N1();
return super.N;
endfunction
endclass
module main;
ext e;
base b;
initial begin
ext e = new();
base b = e; // parent pointing to same child object!
$display("b = %d", b.N); // "3" //call parent function because its not virtual.
$display(b.get_N()); // "3" //call parent function because its not virtual.
$display(e.get_N()); // "4"
$display(e.get_N1()); // "3" - super.N
end
endmodule
Q1) how parent class variable got memory because variable get memory only when object is created.
Q2) If parent is pointing to child then how its printing parent class variable, it should access child variable. (b.N)