Siddarth Cherukumudi wrote:Thank you, for your response,
but my doubt here is
class1 is referring to the object which is no more existing, doesent that cause NPE
please shed some light on this..
As mentioned in the subject, reference variables and the objects that they refer to are two different things. Don't mix them up.
When two different reference variables are pointing to the same object, it just means that the two variables are pointing to the same object. That is all. It doesn't mean that when you change one of the reference variables to point to something else (or in this example, point to nothing), that the other will change. Setting one reference variable doesn't change the other.
Henry