The old value of second is lost. You can make this safe by first assuring that there is no further need of the old value of second or assigning another pointer the value of second . Note that, from a language point of view, these kind of errors are not errors at all. It is just something that the programmer needs to be aware of. The same variable can point to different objects at different times and old values will be reclaimed when no pointer references them.
Novices often make the following error.
It is illegal to cast a reference variable to a class when the object to which the variable then points is not a member of that class or a subclass. It is illegal to cast a reference to an interface type when the object to which the variable then points does not implement that interface. It is possible to cast a variable of one reference type to another reference type if the cast is valid. The cast is checked. Always illegal and caught by compiler.