1, polymorphic definition: Refers to allow different classes of objects to respond to the same message.
2, the realization of polymorphic technology: Dynamic binding, is to judge the actual type of the referenced object during execution, and call its corresponding method according to its actual type.
3: The role of polymorphism: eliminate coupling between types.
4: polymorphic example: Play lol, we all know qwer what the even recruit, but you press the ENTER key, and then press these qwer will trigger a different event, just pure qwer, no special effects.
Three prerequisites for polymorphism:
1, to have inheritance;
2, to have a rewrite;
3. The parent class reference points to the subclass object.
Remember the last one, you can relate to remember the previous. The parent class can point to subclasses, which must be inherited; Why does the parent need to point to subclasses? This is because the subclass overrides the method of the parent class.
But you only use one object, that is, the parent object, which points to a different subclass, you can invoke the specific method of implementing the various subclasses.
The benefits of polymorphism can be naturally elicited here:
1, flexible: embodies the flexible and diverse operation, improve the use of efficiency.
2, simplification: Unified use of an object to call different subclasses, you can simplify the application software code writing and modification process.
There are other benefits as well:
3. Replaceable
4. Extensibility
5, interface.
Implementation of polymorphism in Java: interface implementation, inheriting the parent class for method overrides, and method overloading in the same class.
The polymorphism of Java