C++ | Virtual Functions | Question 6

Predict the output of following program.

filter_none

edit
close

play_arrow

link
brightness_4
code

#include<iostream>
using namespace std;
class Base
{
public:
    virtual void show() = 0;
};
  
class Derived : public Base { };
  
int main(void)
{
    Derived q;
    return 0;
}

chevron_right


(A) Compiler Error: there cannot be an empty derived class
(B) Compiler Error: Derived is abstract
(C) No compiler Error


Answer: (B)

Explanation: If we don’t override the pure virtual function in derived class, then derived class also becomes abstract class.


Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up