Polymorphism Flashcards
What is Polymorphism
The concept that objects of different types can be accessed through the same interface.
Each type can provide its own, independent implementation of this interface.
Static or Compile Time Polymorphism
Method Overloading
Runtime Polymorphism
Method Overriding
Method Overloading Parameter Differences
Need to differ in at least one of these ways
- Different NUMBER of parameters
- Different TYPE of parameters
- (NOT RECOMMENDED; lacks readability) Different ORDER of parameter type.
Method Signature
Different set of parameters for overloaded methods. Allows compiler to identify which method has to be called and to bind it to the method call.
Method Signature
Different set of parameters for overloaded methods. Allows compiler to identify which method has to be called and to bind it to the method call.
Method Overriding
A subclass can override a method of its superclass.
Both methods, implemented by the super- and subclass, share the same name and parameters but provide different functionality.
Super Keyword
It is used to call superclass methods, and to access the superclass constructor. The most common use of the super keyword is to eliminate the confusion between superclasses and subclasses that have methods with the same name.
Late Binding
Runtime determination of which class should be referenced by which method.
When a subclass object is instantiated and assigned to ta superclass variable, it is still a subclass object. Only the superclass methods can be used, but any overridden methods will be called as from the subclass.
3 General Scenarios of Late Binding
- The object is of the superclass type and is referenced as a superclass type.
- The object is of the subclass type and is referenced as a subclass type.
- The object is of the subclass type and is referenced as the superclass type.