Does reference type serve two purposes in object creation? : <p>Suppose you have your standard java example:</p>

<pre><code>class Animal {
// some methods and a constructor are here
}

class Dog extends Animal {
// some methods and a constructor are here
}
</code></pre>

<p>When you create a new dog object, you do</p>

<pre><code>Dog x = new Dog()
 ^
</code></pre>

<p>The reference type 'Dog' that is pointed to has a purpose; it makes x into a reference type variable because x needs to hold a memory address or at least some bit of data that points you toward the Dog object, which is located in the heap. A primitive type would not be able to modify x to perform that purpose. So that's purpose 1 of the reference type.</p>

<p>However, it also serves a different purpose; it modifies the capabilities of the object Dog(). If you wrote</p>

<pre><code>Animal x = new Dog () 
</code></pre>

<p>From my experiments, the object Dog would be able to perform all methods specified in the Animal class, but it would not be able to to perform methods specified in the Dog class. Whereas, a</p>

<pre><code>Dog x = new Dog ()
</code></pre>

<p>Would be able to perform all methods in the Animal class as well as the methods in the Dog class. So clearly, the reference type has some influence on the object's nature itself.</p>

<p><strong>My question: is it true that the reference type serves two purpose? Purpose 1: It allows the variable to hold a memory address or something similar. Purpose 2: It modifies the capabilities of the newly created object. Or am I misunderstanding something?</strong></p>

<p>(If you would like to mark this as a duplicate or close it, I would appreciate it if you took the time to read the question first rather than closing it based on a cursory glance of some keywords in the question. Thank you)</p>
