Hi,
sakthi karthik, the second object that was referred when only c1 is made null is about the Short wrapper object. So I had counted as 4 objects when c2 is made null explicitly.
However, as explained by kesava narayana I understand that there will be only 3 objects created(object refered by c1,object refered by c2, Short wrapper object). Both short references refer to the same object as it has same value.
So according to the initial program, only 1 object i.e. object refered by c1 is eligible for gc.
Nabila Mohammad, though objects are passed by value, if we change the value of instance variable or manipulate any data which the reference variable is referring to, the values are changed (Because copy of reference variable and reference variable pass are same i.e, both are refereing to the same object.) However, if we change the value of reference variable itself it is as good as changing the value of the copy and refernce to the object is lost but does not change the object value. So changing the values refered is differnt from changing the reference.
The link suggested by Stevi Deter helps in understanding it.
Pls correct me if I am wrong. Also, I did not get what error are they refering to in this question (errata thread). Anyone pls clarify.