Function Overriding in C++

Function Overriding in C++

Function Overriding in C++

 

Function overriding in C++ is termed as the redefinition of base class function in its derived class with the same signature i.e. return type and parameters. If derived class defines same function as defined in its base class, it is known as function overriding in C++. It is used to achieve runtime polymorphism.

 

SYNTAX :

public class baseClass {
  access_modifier:
    //overridden function
    return_type functionName(){ }
  };
}

public class derivedClass : public baseClass {
  access_modifier:
    //overriding function
      return_type functionName(){ }
  };
}

 

 

CODE :

//C++ program to demonstrate function overriding
#include <iostream>
using namespace std;

class baseClass {
public:
void print() {
cout << “The Base Function.” << endl;
}
};

class derivedClass : public baseClass {
public:
void print() {
cout << “The Derived Function.” << endl;
}
};

//Driver code
int main() {

derivedClass d1;
d1.print();

return 0;
}

 

OUTPUT:

The Derived Function



 

Topics Covered :

  • c++ function overriding
  • function overriding in c++
  • c++ function overriding exmple
  • c++ program of function overriding
  • function overriding in c++ program
  • c++ function overriding with example
  • function overriding in c++ programming

 

 


 

 


 

Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.

Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.

 

πŸ§‘β€πŸ’»πŸ§‘β€πŸ’»Β Social MediaΒ LinksΒ ofΒ Tech DCodeΒ :

πŸ‘‰πŸ»Β YouTube :Β https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
πŸ‘‰πŸ»Β Instagram :Β https://www.instagram.com/thetechdcode/
πŸ‘‰πŸ»Β Facebook Page :Β https://www.facebook.com/thetechdcode
πŸ‘‰πŸ»Β Twitter :Β https://twitter.com/thetechdcode
πŸ‘‰πŸ»Β Telegram Channel :Β https://t.me/thetechdcode
πŸ‘‰πŸ»Β Tech DCode Linktree :Β https://linktr.ee/thetechdcode
πŸ‘‰πŸ»Β My Personal Handles :Β https://linktr.ee/virtualshivamin

πŸ§‘β€πŸ’»πŸ§‘β€πŸ’»Β Social Media LinksΒ ofΒ SHIVAM SINGHΒ (OWNER) :

πŸ‘‰πŸ»Β Instagram :Β https://www.instagram.com/virtualshivamin/
πŸ‘‰πŸ»Β Facebook Page :Β https://www.facebook.com/virtualshivamin/
πŸ‘‰πŸ»Β Twitter :Β https://twitter.com/virtualshivamin/
πŸ‘‰πŸ»Β Personal Linktree :Β https://linktr.ee/virtualshivaminΒ 

 

Leave a Reply

Your email address will not be published. Required fields are marked *