Hi widjajaf,
Java has two types of variables: primitive and reference.
Primitive types (int, char, boolean, long, etc) have a pre-set memory size. For example, all 'int' values occupy 32-bits in memory. A primitive variable contains the data assigned to it. For example in <code>int i = 5</code> the memory associated with 'i' contains the value '5'.
Objects do not, cannot, have a pre-set size. They can require small areas of memory or very large areas. On the other hand, a
memory address or
reference can have a pre-set size.
The language makes use of this fact by storing an objects memory address in a variable instead of trying to hold the object itself. For example in <code>Object obj = new Object();</code> the object itself is created in an empty spot in memory and then the memory address for that object is stored in the variable <code>obj</code>. <code>obj</code> is a 'reference variable' because it
refers to an object rather than
being the object itself.
In your example, 'r' is a 'reference variable' that holds the memory address for the <code>new Kid()</code> object. When <code>r.method()</code> is encountered the system knows it has to go to the memory address stored in 'r' to locate the actual object.
Hope that helps.
Please read the
JavaRanch Name Policy and re-register using a name that complies with the rules.
Thanks for your cooperation.
------------------
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited October 22, 2001).]