0

what happens at memory level....when one object is assigned to another....
i have written 2 classes.....1st named base class mybase and a subclass named subclass....

now i create object of baseclass...

mybase b = new mybase();
//and now i create object of subclass
subclass c = new subclass();
b=c;

now question is this what happens at memory level....i knw they now start to share same memory location( memory location of c)......so wat abt previous location which was alocated to b.....isnt that anymore.....and may be m having wrong concept of all this...pzl describe it and i have some peculiar observation concerning this matter......will ask after reply to dis thread...plz reply tx in advance!!!!

3
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by bugmenot
0

The instance of base class is left in the cold and it will be removed from memory by Garbage collector of Java. It is like a pointer in C++.

0

"b" and "c" are references (like the previous poster said, kind of like pointers in C) which may point to objects. objects are not values in java; instead, you always manipulate them through references. you have one reference pointing to one object and another reference pointing to another object; then you assign one reference to another, so now they both point to the same object.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.