Given the following code fragment:
What is the output?
Both variables reference the same Pet object, so assigning "Cat" through p1.name updates the object's name. Assigning null to p does not affect p1, which still refers to that object; therefore, both printed values are Cat.
Pet
"Cat"
p1.name
null
p
p1
Cat
Community Discussion