Object vs Reference in Java

前端 未结 8 2083
梦如初夏
梦如初夏 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 04:02

    In computer science, a reference is a value that enables a program to indirectly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing that data is called dereferencing the reference.

    In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure. (With the later introduction of object-oriented programming the same word, "object", refers to a particular instance of a class)

    so obj is a reference and new MyClass() can be seen as an object

提交回复
热议问题