在模拟 OCJP 认证时,我发现了这个问题:
1. StringBuffer s1 = new StringBuffer("abc");
2. StringBuffer s2 = s1;
3. StringBuffer s3 = new StringBuffer("abc");
How many objects are created ?
他们说正确答案是 4,因为他们说:
s1 is one object, s2 is another object,
s3 is another object and "abc" is another String Object .
但对我来说这是错误的,它应该是 3,因为s1
和s2
是同一个对象。你怎么看?