Cannot call derived class method in a function that takes base class as parameter
<p>I have the following problem:</p>

<pre><code>class A {
   void f() {}
}

class B extends A {   
   void g() {}
}

class C extends A {
   void h() {}
}

void foo(A temp)  
{
   temp.g();
}
</code></pre>

<p>I want my foo() function to take a base class parameter, so I can work with B &amp; C. But inside the funciton I have a call to a derived class method, so of course I get an error.<br>
I also tried this inside the foo function:</p>

<pre><code>if(temp instanceof B)
{
   B somevar = (B)temp;
}
else if( temp instanceof C)
{
   C someVar = (C)temp;
}

someVar.g();
</code></pre>

<p>But still I have a compile errors that it doesnt know who someVar is. How could I make this to work ?   </p>

<p>Thanks.</p>
