Skip to content

Tag Archives: Virtual Functions

In this article, we will discuss the behavior of Virtual Function in the derived class and derived class from the Abstract Base Class in C++.… Read More
Virtual Function in C++ A virtual function a member function which is declared within a base class and is re-defined(Overriden) by a derived class. When… Read More
Predict the output of following C++ program #include<iostream> using namespace std;    class Base { public:     virtual void show() { cout<<" In Base \n"; }… Read More
#include <iostream> using namespace std;     class A { public:     virtual void fun() { cout << "A::fun() "; } };     class B: public A… Read More
Predict the output of following C++ program. Assume that there is no alignment and a typical implementation of virtual functions is done by the compiler.… Read More
Can static functions be virtual? Will the following program compile? #include<iostream>  using namespace std;       class Test {    public:       virtual static void fun()  { }… Read More
#include<iostream> using namespace std; class Base  { public:     Base()    { cout<<"Constructor: Base"<<endl; }     virtual ~Base()   { cout<<"Destructor : Base"<<endl; } }; class Derived: public Base… Read More
Can a destructor be virtual? Will the following program compile? #include <iostream> using namespace std; class Base { public:   virtual ~Base() {}    }; int main()… Read More
Can a constructor be virtual? Will the following program compile? #include <iostream> using namespace std; class Base { public:   virtual Base() {}    }; int main()… Read More
#include<iostream> using namespace std;    class Base { public:     virtual void show() = 0; };    class Derived: public Base { public:     void show() {… Read More
Predict the output of following program. #include<iostream> using namespace std; class Base { public:     virtual void show() = 0; };    class Derived : public… Read More
#include<iostream> using namespace std;    class Base { public:     virtual void show() = 0; };    int main(void) {     Base b;     Base *bp;     return 0;… Read More
Which of the following is true about pure virtual functions? 1) Their implementation is not provided in a class where they are declared. 2) If… Read More
Output of following program #include<iostream> using namespace std;    class Base { public:     virtual void show() { cout<<" In Base \n"; } };    class… Read More
Predict output of the following program #include<iostream> using namespace std;    class Base { public:     virtual void show() { cout<<" In Base \n"; } };… Read More