Inheritance and Object creation, Theoretically and in Real

前端 未结 3 1081
庸人自扰
庸人自扰 2020-12-16 06:44

Lets say I have a class A.java,

\"enter

When I will execute a con

3条回答
  •  我在风中等你
    2020-12-16 07:21

    I have not read this anywhere but its my experience. When you call new D(), the constructor chain begins, it first creates an java.lang.Object and then extends it to an A, I mean after creating the Object (which is root of all objects), A is initialized on it, by adding memory for A's members, including fields and methods (which are a pointer to some code!). And then it extends to B and so on.

    In the process of extension if a method is overriden, the method pointer in the object will point to new code.

    It will be only one reference to D.

提交回复
热议问题