Confused

I was reading a book on Java and got really confused...see when we create

Class abc a,b;

a=new abc();

b=a;

both b and a point to the same object and there are no copies created....

Please tell me where am I goin wrong in the following arguement

class emp

{

public emp(String s)

{

name=s;

}

public getname()

{return name;}

}

when I call emp e = new emp("ABC") the String s of the constructor now points to the string "ABC" which is assigned to name. Since the constructor ends s gets destroyed. So how come getname is able to return ABC.

[639 byte] By [crash_overridea] at [2007-11-27 8:53:42]
# 1
The object still exists. It's the reference that dies
georgemca at 2007-7-12 21:11:38 > top of Java-index,Java Essentials,Java Programming...
# 2
Is there anyway I can destroy an object like delete in C++
crash_overridea at 2007-7-12 21:11:38 > top of Java-index,Java Essentials,Java Programming...
# 3
No. You can stop referring to it, which would make it eligible for garbage collection, but there's no guarantee it will ever be collected. You don't really need to worry about these things in Java, though. That's why it takes care of so much memory management for you
georgemca at 2007-7-12 21:11:38 > top of Java-index,Java Essentials,Java Programming...
# 4
thanks a lot for ur replies....
crash_overridea at 2007-7-12 21:11:38 > top of Java-index,Java Essentials,Java Programming...
# 5
No problem
georgemca at 2007-7-12 21:11:38 > top of Java-index,Java Essentials,Java Programming...