Hi John,
Can you please explain me this
class Animal
{
void makeNoise(){System.out.println("generic noise");}
}
class Dog extends Animal
{
void makeNoise() {System.out.println("bark");}
void playDead() {System.out.println( "roll over");}
}
class CastTest2
{
public static void main(
String [] args)
{
Animal [] a = {new Animal(), new Dog(), new Animal()};
for(Animal animal : a)
{
animal.makeNoise();
if(animal instanceof Dog)
animal.playDead();
}
}
}
When i compile this code compiler gives an error at animal.playDead()
Cannot find symbol : method playDead() at class Animal animal.playDead();
Does it mean at compile time "animal instanceof Dog" is true?
Only when "if" statement is true does the compiler go to next statement.
Can you please explain.
Thank You