This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
The "compile-time type" of a variable is the type it is declared as. The "runtime type" is the type of the actual object the variable points to. So in the following line of code:
The compile-time type of "o" is Object, and its runtime type will be String. The compile-time type governs which methods can be called, while the runtime type governs what happens during the actual call. You can write
because Object has a hashCode method, but you can't call
because although String has an indexOf() method, Object doesn't, and so the compiler won't let you call it. Now, when the "hashCode()" function is actually called, it's String.hashCode() that gets executed. That's polymorphism, and if you haven't learned about that yet, you will soon!