function overriding classes in oop cplusplus

What is member functions overriding?

Function overriding means to have the two or more functions with same name and with same signatures. Same signature means that to have the same name, same number of parameters and same data types.

Give example of member functions overriding?

Suppose Class A and class B have two functions with same name and same parameters . Then we can say that the function in class B overrides the function in class A.

Example program:

Serial# Code
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

#include<iostream>

using namespace std;

class A

{

public:

void print()

{

                cout<<“print function for class A”<<endl;

}

};

class B : public A

{

public:

void print()

{

                cout<<“print function for class B”<<endl;

}

};

int main()

{

                B object;

                object.print();

                object.A :: print();

}

 

Here we have two functions of print() with  same name and with same parameters…This is actually the function overriding.

Fazal Rehman Shamil
Welcome to all friends. The reason for our success is only your love for T4Tutorials. Our team is always available to answer your queries regarding any kind of confusions or discussion regarding your study and career matters. For discussion with us please join our facebook group "T4Tutorials.com". The link of the group is mentioned below. Thanks and love to all for connecting with us. We are nothing without you. Love you all.....
https://web.facebook.com/groups/2066136233601097/