Hi friends ,
In the following code , in the cast class , i have explicitly type-casted dog reference to Animal type . But still when i invoke , a1.makenoise () , Dog class is invoked , not the Animal class . Can anyone explain the reason please ??
Thanks in advance .........
class Animal
{
void makenoise()
{
System.out.println("in animal : makenoise ");
}
}
class Dog extends Animal
{
void makenoise()
{
super.makenoise();
System.out.println("In dog : makenoise ");
}
void playdead ()
{
System.out.println ("in dog : playdead ");
}
}
public class cast
{
public static void main (
String [] args )
{
Dog d = new Dog ();
Animal a1 = d ;
d.makenoise();
a1.makenoise();
}
}