Skip to content
Related Articles

Related Articles

C++ | Virtual Functions | Question 5
  • Difficulty Level : Hard
  • Last Updated : 12 Oct, 2013




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


(A) There are compiler errors in lines “Base b;” and “Base bp;”
(B) There is compiler error in line “Base b;”
(C) There is compiler error in line “Base bp;”
(D) No compiler Error


Answer: (B)

Explanation: Since Base has a pure virtual function, it becomes an abstract class and an instance of it cannot be created.

So there is an error in line “Base b”.

Note that there is no error in line “Base *bp;”. We can have pointers or references of abstract classes.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :