Compile-time polymorphism

Sample Code

using namespace std;  

class Multiply  

{  

   public:  

   int mul(int a,int b)  

   {  

       return(a*b);  

   }  

   int mul(int a,int b,int c)  

   {  

       return(a*b*c);  

  }  

 };  

int main()  

{  

    Multiply multi;  

    int res1,res2;  

    res1=multi.mul(2,3);  

    res2=multi.mul(2,3,4);  

    cout<<"\n";  

    cout<<res1;  

    cout<<"\n";  

    cout<<res2;  

    return 0;  

}  

Output

Run-time polymorphism

Sample Code

using namespace std;  

class Base  



    public:  

    virtual void show()  

    {  

        cout<<"Wikitechy";  

     }  

};  

class Derived:public Base  

{  

    public:  

    void show()  

    {  

        cout<<"Welcome to Wikitechy";  

    }  

};  

  

int main()  

{  

    Base* b;  

    Derived d;  

    b=&d;  

    b->show();  

                return 0;  

}  

Output

Categorized in:

C++

Tagged in:

, , , , , , , , , , ,

Share Article:

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO