+ 1

Can someone explain how this works?

so variables reference objects and are not objects themselves, so i always thought when you assigned the reference variable to null, you could no longer access that references variables, why does that change when you have a class variable, what exactly occurs when you write anObject = null; https://code.sololearn.com/c15790KJXS2i/?ref=app

13th Sep 2018, 4:18 PM
StealthyTaco
StealthyTaco - avatar
1 Réponse
+ 3
In your provided code reference b is of Type A and when you set the reference variable b to null although the reference is no longer pointing to an object, due to static binding b can call A's static methods and variables. In other words when you write b.x it doesn't matter to what b is referencing all that matters is of what type b is. You might as well write A.x and you'll get the same output.
13th Sep 2018, 6:14 PM
vatsal uppal