What is the polymorphism?
-
This week I'll go to a job interview and there will be questions from OOP. One of the questions will be about polymorphism and I want to give a smart answer. Can you give me some ideeas?
-
Answer:
Polymorphism is a major tool in OOP. There is no simple way to explain it, but I'll try. In short, polymorphism means that when an objects function or method is called, if that object is actually a child object, the child objects implementation of said function will be called instead. Imagine you have a class called "Animal" which has a function called "talk", which does nothing. Then you have two child classes called "Dog" and "Cat". "Dog" overrides the "talk" function to print out "woof". "Cat" overrides the "talk" function to print out "meow". Let's say you have an array of "Animal" objects which you iterate through, calling "talk" on each one. If any of them are "Dog" objects, instead of doing nothing, it will print out "woof", same with "Cat" objects.
Radu at Yahoo! Answers Visit the source
Other answers
Check this out : http://en.wikipedia.org/wiki/Polymorphism_(computer_science)
jacknbx2006
Compile time polymorphsim and run-time polymorphism function name overloading we will be having a set of functions with same name but differing in argument/types. When we make a function call, compiler decides which function (with the same) has to be called really during the compilation itself. Even, we can think of template functions also compile time polymorphism. Run-Time polymorphism We know that we can assign derived class address to base class type pointer (even we can reference also not only address). class A { public: void show(){} } class B:public A { } class C:public A { } main() { A *P; B X; P=&X; P->show(); Now show is called with B type of object as P is currently point to B type object. C T; P=&T; P->show(); Now, show is called with C type object as base class pointer to pointing to C type object } That is, when we say P->show(), at that instance to whatever type of object it is pointing with that show is called. This is, run-time polymorphsim Do link with virtual functions also here
James Bond
Related Q & A:
- What is the Cytoskeleton and what are its functions?Best solution by Yahoo! Answers
- What is an example of relational data and what is an example of a document?Best solution by people.cs.pitt.edu
- What is tennis elbow and what can help the pain?Best solution by webmd.com
- What is GRE? What is its significance?Best solution by Yahoo! Answers
- What day will brasil play against argentina. And what time on what channel? Will it be telemundo?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.