Explain Compile Time and Run Time Polymorphism. - Computer Science 1

Answer in Brief

Explain Compile Time and Run Time Polymorphism.



Polymorphism refers to identically named methods (member functions) that have different behavour depending on the type of object they refer. Polymorphism simply means “one name, multiple forms.

Runtime polymorphism :
(1) In some situations, it is nice to select appropriate member function to be invoked while the program is running. This is known as runtime polymorphism.
(2) The types of polymorphisms and their examples are shown in following figure:

Here, show ( ) function is used to print values of object of both the classes A and B. The prototype of show ( ) is the same in both the places, the function is not overloaded and therefore static binding does not apply.
(3) In such situations, the appropriate member function can be selected at runtime and it is known as runtime polymorphism.

Compile Time Polymorphism :
(1) Function overloading and operator overloading are the examples of compile time polymerphism.
(2) In this case, the overloaded member functions are selected for invoking by matching arugments, both type and number.
(3) This information is known to the compiler at the compile time and, therefore the compiler is able to select the appropriate function for a particular call at the compile  time itself. This is known as compile time polymorphism.
(4) Compile time polymorphism is also called as early binding or static binding or static linking. Early binding simply means that an object is bound to its function at  compile time.

Concept: C++ Programming
  Is there an error in this question or solution?
2015-2016 (March)



      Forgot password?
Use app×