Basically, if you declare something as a Bird, the only things the compiler is "allowed" to know is that it has the methods defined for Bird. It's not allowed to know about any methods declared for any subclasses of Bird (unless you use a cast).
Suppose you were to say
Bird b = new Falcon();
someMethod(b);
and then, in someMethod:
public void someMethod(Bird b) {
b.fly();
}
This is essentially the same thing you're doing. But the only thing someMethod knows about b is that it's some kind of Bird. It can't tell, at that point, whether it's a Falcon, or something like an Emu or Kiwi that doesn't have a flight method (since someMethod could be called from some other place in the program).
Sure, it might be possible for the program, when it sees b.fly(), to check at run time whether this kind of bird has a fly method, and throw an exception if it doesn't. Some languages do that. Java doesn't.
Also, if you're thinking that the compiler should know in this case:
Bird b = new Falcon();
b.fly();
that b is a Falcon, because it just created it as a Falcon: that doesn't work, because it would require overly complicated language rules to allow a compiler to see that b.fly() will always work in this case, but won't always work in other cases. Language rules need to be kept fairly simple and consistent, to ensure that programs will work on any compiler that meets the standard.
However, if you use a cast, you can get at methods of the subclasses:
Bird b = new Falcon();
((Falcon)b).fly();
This says to check (at run time) whether b is a Falcon. If it is, you can now use the methods defined for Falcon. If it isn't, you'll get an exception.
BirdDoesn't have aflymethod specified in its' public interface.Bird, Java will only let you invoke methods on it that it knows all Birds have. You didn't declare a methodfly()on Bird, so as far as Java knows, this Bird could be one that doesn't have that method -- and thus, it won't let you invoke it. Java doesn't know at compile time thatbis specifically a Falcon, because you explicitly told it that it's just some kind of Bird.