not to be stated as duplicate this question address where the field lives in the program not is it inherited or not or if it inherited but not accessible.
please continue reading to understand
in the example below we see that the dog object can access the animal private field "name" throw the use of a public getter "getName" but is not the private fields are not inherited so where the field name is living
from searching i realized that only one object is created from the sub class and not two one to the sub and one to the super to hold the private fields.
focus now >> we all know that a public setter in any class can set its private fields but we know where the field is living ! in the object of the class
so my question in abstract is as follow
where the accessed private field is living in the sub class created object !
Where is it !
public class Animal {
private String name ;
public Animal (String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
}
public class Dog extends Animal {
public Dog(String name) {
super(name);
}
}
public class Hello {
public static void main(String[] args) {
Dog mmms = new Dog("mmkk");
System.out.println(mmms.getName());
}
}
edit : i think this question may be stated as
where does the private fields of the parent class live if it is not inherited ?
question name changed for more understanding from
How the sub Class object get access to the private members of its super class from public getters?
to
Where do private fields of super class live when accessed from sub class using public getter ?