* Objects are smart enough to be dynamic. Specifically, have the capacity to react differently depending on the situation .
* This is important because it makes the API reliable and easy to understand for the next developer .
* Here is an example. Suppose you have a method called “print ()”.
* The first question you could ask is, ‘what does this method of printing images, text, or what ?”
* Well using “polymorphism”, an object can be done to handle any situation with the same method name. Therefore, depending on what the object is called on the press, it will be able to print .
* Instead of having separate methods as PrintPictures (), printLetters (), and printNumbers () that has a unified print () and the object itself determines how to handle different types of situations .
< > In a nutshell, polymorphism is improved method call. In short, through inheritance and flow of Animal / mammals / Cat example :
void test ()
(
Simon = new Cat Cat creature Animal ();
= Simon / / upcasting < > Creature.eat () / / = Cat.eat
= new Dog Dog Rover ();
/ / Rover safe upcast reference to animals
feed (Rover);
feed (Simon);
)
void feed (Animal )
(
/ / Creature.eat () = Cat.eat ()
/ / feed (rover) = Dog.eat ()
/ / feed (Simon ) = Cat.eat ()
a.eat ();
)
In this case, Animal.eat () is polymorphic .
Polymorphism: “Calling a Java / virtual method using a superclass reference to a more generalized real object invokes a method in the real object (the most specific subclass), using a bottom-up search mechanism “.
Tutorial Java, the definition of polymorphism indicates that the name of the function of overload is the same thing, which is an incorrect statement “.
Related Posts
- OOP, an Introduction to Object-Orientation
- Inheritance Syntax in C++ programming language
- The best job on the world 2 – earn $100.000 with great communication and swimming
- Inheritance between Objects
- Classes – Ruby on Rails tutorial
- POO, an introduction to object-oriented programming
- SWFFix, named to replace SWFObject
- Course Schedule – Development of algorithms using the Object Oriented Programming
- 5 Reasons Why RSS readers that are still effective
- Arrays and Iteratiors – Ruby on Rails tutorial
- Objects in POO
- Hardware-xperiments 2
- More about methods – ruby on Rails tutorial