Object vs Reference in Java

前端 未结 8 2093
梦如初夏
梦如初夏 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:11

    Sometimes you'll hear people say "Design an method that takes an object as a parameter and..."

    If you're new to programming, and especially with Java, such statements can lead to some confusion. These people are using the word "object" to refer to an instance of a class in very general OOP terms, not necessarily Java specific.

    When we're talking specifics about Java and the code you have there, it is a reference to an instance of MyClass, which is NULL.

提交回复
热议问题