Where does java reference variable stored?

前端 未结 6 668
醉话见心
醉话见心 2020-12-06 02:29

How does Java\'s reference variable stored? Is that work similar to C pointer?

what I mean by reference variable is myDog in this code

Dog myDog = ne         


        
6条回答
  •  借酒劲吻你
    2020-12-06 02:52

    It is exactly the same as a C pointer, and almost always on the stack. In C the object itself is on the heap when you say new Dog(); but the Dog * myDogP pointer (4 or 8 bytes) need not be on the heap and is usually on the stack.

提交回复
热议问题