What is the difference between an Object , Reference ID , and Reference Variable in Java?

前端 未结 8 836
余生分开走
余生分开走 2020-11-30 13:24

What is difference between the following in java :

  1. Object

  2. Reference ID

  3. Reference Variable

When I see sta

8条回答
  •  时光取名叫无心
    2020-11-30 13:44

    Car c=new Car();

    Object is nothing it is just a buffer or memory in heap where non static data members gets the memory.

    Reference ID is generated by new operator in the stack and it is a memory location which contains the memory location of an object in hashcode form. Reference ID is the only way to reach the object. Reference ID is generated because there is a rule in java that memory allocated at run time does not have any name and we all know that objects are created at run time so they also have no name and we need a unique ID to perform operation on that object that's why there is a unique Reference ID in java for each object.

    In above example c is a reference variable which store the reference ID.

提交回复
热议问题