Object vs Reference in Java

前端 未结 8 2087
梦如初夏
梦如初夏 2020-12-03 03:41

In Java, if I declare,

MyClass obj;

Is obj called a \"reference\" or an \"object\". I am not instantiating class here.

8条回答
  •  暖寄归人
    2020-12-03 03:57

    obj is a Reference to an instance of MyClass.

    Currently, that Reference is NULL because you haven't assigned it to refer to any instance.

    Technically MyClass must be a subclass of Object, so it is possible to say that obj is a Reference to an instance of Object as well.

提交回复
热议问题