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!!!!

Recommended Answers

All 2 Replies

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++.

"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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.