After searching on the web I did not found yet a good and comprehensive answer about where exactly the instance variables are places inside Java Memory Model. For example we have this code (with shadowing declaration of variables):
class A {
int var = 1;
void m() {
System.out.println("\'m()\' is called from class A");
}
}
class B extends A {
int var = 5;
void m() {
System.out.println("\'m()\' is called from class B");
}
}
public class Class1 {
public static void main(String args[]) {
A aref = new B();
aref.m();
String s = (aref.var)==1?"A":"B";
System.out.println("\'var\' is called from class " + s);
}
}
Output of this code is:
'm()' is called from class B
'var' is called from class A
Now the question is not how inheritance works in Java but where in the Java Memory Model this instance variable resides? Please argument your answer.
Thanks