Being not a programmer, I would like to understand the following code:
A a=new A();
B a=new B();
a=b;
c=null;
b=c;
If the variables are holding only reference, will ‘a’ be null in the end?
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.
You need to divorce two concepts in your mind; the reference and the object. The reference is essentially the address of the object on the managed heap. So:
This doesn’t impact “a” or “A”. “a” still holds the address of the B that we created.
So no, “a” is not null in the end.