My question is related to this SO question.
My first question is as far as I can understand number of objects are 3, s1, s3 and "abc" (I posted an answer to this question). If some one says it is 4. How that happens there?
consider my following class.
public class ObjectCount {
static int i;
ObjectCount() {
System.out.println(++i);
}
public static void main(String args[]) {
ObjectCount obj1 = new ObjectCount(); //i=1
ObjectCount obj2 = new ObjectCount(); //i=2
ObjectCount obj3 = obj1; // obj3 is also an object refer same as obj1
}
}
有多少物体?再次我认为它应该是2。那么上面的SO帖子答案可以是4个对象吗?有人可以帮我弄清楚我在哪里得到了一些不正确的观点吗?
仅供参考: 现在之前的问题已在该帖子上修复。不正确的答案已正确。那里有 3 个对象。不用担心。