into a java variable{name,value,address,type}.

In any scripting or compiled language, OO or otherwise, a variable is a trio of { name, value, address }. In java, we have to remember the type and actual object behind a variable. “address” and “object” are slightly diffferent views of the same entity.

In java, it’s instructive to see a variable in terms of a pointer and an onion. Multiple remote controls can point to the same chunk of memory.

a pointer is a reference and a remote control, with
* a unique name
* a type defined in a type hierarchy. A type can be an interface type.
* supported services of the type. We mean instance methods.

an object is a /pointee/referent/ and an onion in memory with
* a unique address. There’s no address for the base object nested in an onion. Not possible to have a variable pointing to the base objects inside an onion.
* no name
* fields
* methods, possibly overriden or hidden.

Pointer Casting (up or down) affects the type, the fields and methods. When up-casting from subtype C to a basetype B,
– address and name remain
– instance/static fields may disappear, since they may be undefined in parent class C
– instance methods remain, even if they are overriden in a subclass C. Polymophic runtime binding via vptr
– static methods? Yes affected in a subtle way. see blog on [[ static binding ]]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s