This blog is about providing theory as well as simple executable codes of different programming languages such as java, C, C++, and web programming, etc. This blog will be helpful to the IT students to learn about programming.

Showing posts with label virtual function. Show all posts
Showing posts with label virtual function. Show all posts

Wednesday, March 1, 2023

What is Virtual function? Write a program showing the example of virtual function.

March 01, 2023 0
 A virtual function is a member function in a base class that can be overridden in a derived class. When a virtual function is called using a pointer or reference to a base class object, the appropriate derived class function is called based on the type of the object pointed to or referenced.Here is an example program showing the use of virtual function:#include <iostream>using namespace std;class Shape {   protected:     ...

Friday, February 17, 2023

When do we use virtual function? Differentiate early and late binding.

February 17, 2023 0
Virtual functions are used in object-oriented programming to achieve polymorphism. In particular, virtual functions are used in the following scenarios:When a base class pointer points to an object of the derived class, and we want to call a member function of the derived class through the base class pointer. This is known as runtime polymorphism, and it requires the use of virtual functions.When a base class has one or more functions that are intended to...

Slider Widget