Polymorphism
Polymorphism means "many forms": the same method call can do different work. Java has two kinds. Overloading (several methods with one name and different parameters) is settled by the compiler before the program runs. Overriding (a subclass replacing a method it inherited from its parent class) is settled while the program runs, by the real type of the object. This section covers the rules of each, casting, and code-output puzzles.
After this section you can state both kinds with their exact rules and predict what overloaded and overridden calls print.
Topics in this section
- Overloading, chosen at compile time
- Overriding and its rules
- Dynamic method dispatch and hidden fields
- Static methods are hidden, not overridden
- Upcasting, downcasting and ClassCastException
- Overload resolution surprises