I am teaching myself Java, and one of the review exercises in my book asks for the difference between an "object" and an "object variable."
I know what an object is (a specific instance of a class), but I can't seem to find the term "object variable" anywhere in the book (no answers section) or on the internet.
Does anyone know the meaning of this term?
I'll bite.
The Object is the instance itself, whereas the Object Variable is the reference to the Object.
Here's a contrived example:
Object o = new Object(); Object ref1 = o;
In his case, there is a single instance of the Object, but it is referenced by two Object Variables: o and ref1.
When an Object is no longer referenced by an Object Variable, the Object is garbage collected.
It's a synonym of "instance variable":
class A { static int m; // <-- class variable int n; // <-- instance variable ... }
Evidently, this term is not so commonly used, and it would better to avoid any potential ambiguities by just sticking with "instance variable".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With