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

前端 未结 8 801
余生分开走
余生分开走 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:57

    Object is nothing it is just a memory area or buffer in a heap area where all the instance data members of a class are getting a memory.

    Emp e = new Emp();

    in the above statement e is a reference variable which hold the reference id of the object, however in for security purpose java is not allowing anyone to get the id of actual object it also can be self explanatory as we are using word reference id which redirects us that we are not getting the actual id of our object instead just a reference of it.

    also reference id would be nomenclature as classname@hexadecimal representation of the # code of object.

    0 讨论(0)
  • 2020-11-30 14:02

    I just made a program for displaying reference ID of an object.

    class abc
    {
    
       int a=10;
       int b;
    }
    
    class t extends abc
    {
    
       public static void main(String args[])
       {
         abc A=new abc();
         System.out.println(""+A);
       }
    }
    

    output : shockingly a hex string :

    "abc@52e922"

    Java maps the actual location of an object at a separate place in form of a hex string which is known as reference ID. It never displays actual location of it's object stored in the memory.

    0 讨论(0)
提交回复
热议问题