How can a single reference variable access to all object fields?

后端 未结 4 1764
一生所求
一生所求 2021-01-13 17:22
Animal myAnimal = new Animal();

I have this code above. As far as I know, it will do these things :

  1. An animal object will be created
4条回答
  •  旧巷少年郎
    2021-01-13 17:40

    When an object is created, java does not share its Actual Memory Address with refrence variables instead of that Java creates an index number for your object,which is passed to the reference variable of that object. So, you are able to access your object with help of that index number. Further your object hold the refrences of its children and help you to access them.

提交回复
热议问题