In: Computer Science
c++
Define polymorphism. What is the benefit of using pointers with
polymorphic functions?
Polymorphism can be defined as a code that is processed or run multiple times to achieve the desired output. There are two types of polymorphism run-time(Method overriding) or compile-time(Method overloading).
Benefits of Polymorphism
E.g
#include <iostream> 
Using namespace std: 
class student {  
   public: 
   void show() {    
      cout << "Hello Welcome to class"; 
   } 
}; 
class School:public student { 
   public: 
   void show() {   
      cout << "Please Study well"; 
   } 
};  
int main() {   
   student x;        // Base class object 
   school y;        // Derived class object 
   x.show();   // student class method is called 
   y.show();   // school class method is called 
   return 0; 
} 
Output
Hello welcome to class
Please study well