Are these two object the same
Posted on 2005-03-27
I have a little question here:
MyClass obj1 = new MyClass();
MyClass obj2 = new MyClass();
static Stack stack = new Stack();
I insert both objects into the stack like:
then I take both objects out of the stack,
newObj1 = stack.pop();
newObj2 = stack.pop();
if I compare these two objects by:
if(newObj1 == newObj2)
will the result be the same?
i though the result would be different, because two objects refer to different memoery location even inside the stack.
I tested and got the "same" answer, but does not
understand why it's the same,, can anyone give me an explanation?I