posted 18 years ago
1. StringBuffer s1 = new StringBuffer("abc");
2. StringBuffer s2 = s1;
3. StringBuffer s3 = new StringBuffer("abc");
How many objects are created ?
1. 0
2. 1
3. 2
4. 3
Answer : 4
How??
Because,
s1,s2 & s3 are references to the object not the objects themself.The s2 will refer to the object created by the s1,then how 3 objects are created? the ans should be 3rd option 2.
Plz explain me if I am wrong.