I've read through some articles about static binding and dynamic binding in Java. And I have the following question (I've searched a lot but not found any mention about it yet):
For example, I have the following lines of code:
Person a = new Student(); // Student is a subclass of Person
a.speak();
What we've already known is that at compile-time, the compiler will checks whether there exist method definition for speak() in class Person and call it if it exists. And at run-time, it will call the speak() method of the actual object to which a is pointing (The actual object in this case is clearly Student)
So my question is why it doesn't directly call the speak() method of class Student at compile-time, but wait until run-time to do that? Are there any reasons behind this?