Hi,
I want to understand memory allocation while overriding member in concept of inheritance.
My code is -
class a;
int i = 1;
endclass : a
class b;
int i = 2;
endclass : b
module top;
a a1;
b b1;
int p1,p2;
initial begin
b1 = new;
a1 = b1;
p1 = a1.i;
p2 = b1.i;
end
endmodule
Now I understand here that as there is only one memory created as only one new is called. And b1 is just assigned to a1.
Result - p1 will be 1 and p2 will be 2.
Question - If there was only one memory allocated here, how come i got a1.i as well as b1.i later ?
As per my understanding, If there was only one memory created in this case, ideally either value of i should get overloaded & i should be able to access any one value of i only rather than both.
Please explain me memory allocation while overriding members hereā¦