How the instantiation is happening in this java code snippet
<p>my code is</p>

<pre><code>class Alpha
{
public void foo()
    {
    System.out.print("Alpha ");
    }
}

class Beta extends Alpha
{
public void foo()
    {
    System.out.print("Beta ");
    }

public static void main(String[]args)
   {
    Alpha a = new Beta();
    Beta b = (Beta)a;

    a.foo();
    b.foo();
   }
}
</code></pre>

<p>Output:-</p>

<pre><code>Beta Beta
</code></pre>

<p>i am new to java and this kind of instantiation i have come across for the first time and thats why i am not able to understand why the output is not </p>

<pre><code>Alpha Beta
</code></pre>

<p>if 'a' is the object of class Alpha then why not Alpha's method is being called?</p>

<p>Please help me out.</p>
