TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Saturday 15 August 2020

Runtime polymorphism In C++ | Runtime polymorphism In C++ Example | Runtime polymorphism In C++ In Hindi

 

Runtime Polymorphism In C++

This type of polymorphism is achieved by Function Overriding.      

    ·       Function Overriding      


image of runtime polymorphism in c++
Fig: Runtime Polymorphism In C++

   

      1.   Function overriding 

 Function overriding on the other hand occurs when a derived class has a definition for one of the member functions of the base class. That base function is said to be overridden.


Program:

#include<iostream.h>

#include<conio.h>

class base

{

public:

          virtual void print ()

          {

cout<< "print base class" <<endl;

 }

void show ()

          {

 cout<< "show base class" <<endl;

 }

};

class derived:public base

{

public:

          void print ()       

{

 cout<< "print derived class" <<endl;

}

void show ()

          {

 cout<< "show derived class" <<endl;

 }

};  

void main()

{

          base *bptr;

          derived d;

          bptr = &d;

          bptr->print();  

          bptr->show();

getch();

}


Output:

Print derived class

Show base class


No comments:

Post a Comment