Getting it right from the beginning : Object vs Reference
Joined: Apr 17, 2003
Would someone be willing to tell me if I have forgotten anything in this example code? I'm trying to comment on everything so that I get this right from the get-go.
I really appreciate everyone's help. Leo [ edited to reduce the left-right scrolling -ds ] [ January 31, 2004: Message edited by: Dirk Schreckmann ]
Joined: Dec 10, 2001
Writing similar example programs is exactly what I started doing when I first began learning Java. It's a practice I still hold today, as I learn some knew API or technology. It looks like you're understanding things. //Object variables contain a null pointer upon declaration, //meaning that they don't point to any created object. Not exactly. Instance member variables, static class member variables, and array members are always automatically initialized upon declaration. Had your example apple variable been simply declared in a method, it would not have been initialized automatically to null as it is when it's an instance member. If you haven't already stumbled across it, I'd recommend a read of a couple JavaRanch Campfire Stories - "Cup Size" and "Pass-by-Value Please" - just to help clarify the situation.