“Object” vs “Object Variable” in Java?

后端 未结 6 1572
春和景丽
春和景丽 2021-02-01 19:01

I am teaching myself Java, and one of the review exercises in my book asks for the difference between an \"object\" and an \"object variable.\"

I know what an object is

6条回答
  •  一生所求
    2021-02-01 19:56

    I found something that help you too. There are few words like object, object variable and object reference.

    Object variable and object reference are similar in the way that object variable stores the reference of an object where as object reference describes the location of an object. (You might be confused here so just consider them as same)

    consider an example::

    Class Car{
    ....
    ....
    }

    Car AudiQ7; //S1
    Car AudiQ8 = new Car(); //S2

    Here in S1 we created only object. Means it does not refer to memory.

    In S2 we created an object variable/reference means it refers to memory location.

提交回复
热议问题