Please read this. you're much more likely to get help if your posts contain real words, and not things like "plz" and "r".
Well said.
in this pgm first we r printing s1 value.after we are assigning s2 value to s1.my doubt is after assgining the s2 value to s1 it is eligible for garbage collection r after making s1 to null.
Yes. Object referenced by s1 will be eligible for Garbage Collection after the assignment.
how many objects r garbage collected?ans is 1.i can't understood how answer is one.
public class X {
2. public static void main(String [] args) {
3. X x = new X();
4. X x2 = m1(x);
5. X x4 = new X();
6. x2 = x4;
7. doComplexStuff();
8. }
9. static X m1(X mx) {
10. mx = new X();
11. return mx;
12. }
13. }
Only the object referenced by x2 will be garbage collected, since it has no reference to it after the x2=x4 statement.