Join Our WhatsApp Group Join Subscribe Now!

Object Oriented Programming Using C++ (313304) Practical No.21: Write programs to implement virtual function

Object Oriented Programming Using C++ (313304) Practical No.21: Write programs to implement virtual function

 Object Oriented Programming Using C++ (313304) Practical No.21: Write programs to implement virtual function

Object Oriented Programming Using C++ (313304)


The concept of virtual function helps to learn the idea of run time polymorphism in C++.

Exercise:

1. What is function overriding?

Answer:

Function overriding is a type of polymorphism in which we redefine the member function of a class that it inherited from its base class. The function signature remains the same but the working of the function is altered to meet the needs of the derived class. So, when we call the function using its name for the parent object, the parent class function is executed. But when we call the function using the child object, the child class version will be executed.

2. Write output for the following code:

Answer:

Output:

C::fun() called

3. There are the following statements that are given below, which of them are correct about virtual functions in C++?

Answer:

2. A and B

Practical Related Questions

1. Define a class parent in which use read function, define another class child use same read function. Display the data of both the read function on output screen using virtual function.

Answer:


2. Write a program that shows the use of function overriding.

Answer:


3. Complete the following table:


Conclusion

We completed Object Oriented Programming Using C++ (313304) Practical No.21 and Write programs to implement virtual function.

About the Author

Hi everyone, I'm Suraj Diware, and I'm passionate about helping students succeed in MSBTE programs. This blog is dedicated to providing clear and concise explanations of MSBTE curriculum topics, along with practical tips and resources to sup…

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.