Dog d=new Dog();
In the above line which is object and which is reference variable? or Whether object and reference variable are the same?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
dis a reference to aDogobject instance.Object instances and references are not the same; references point to object instances.
To illustrate, you can do
now you have 2 references,
dandd2, that point to the same underlying instance ofDog.Now if you do
d2points to the first dog you created, anddpoints to the second (where it originally pointed to the first.) This statement creates a new object instance, and assigns it to the originalDogreference.