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

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

    Emp e
    

    This statement creates a reference variable 'e' in the stack.

        new Emp()
    

    This statement creates an object in the heap. An object is just a buffer or we can say "a chunk of memory". Hence , a buffer gets reserved in the heap. Thus the statement,

       Emp e=new Emp() 
    

    passes the reference id of that object created in the heap to the reference variable 'e'.

提交回复
热议问题