I was wondering what would be the advantage of a class variable storing a reference to an object rather than storing the object directly in its memory location?
Does it have to do with memory issues or is it a security issue.
I tried looking around, i could not find this question.
Thanks.
Java stores Object in heap memory but from code we need to access that Object using some handle, and so is the reference
Also while GCing when there is no active reference object is no longer needed and will be GC ready