Q) Which is the correct declaration of pure virtual function in C++
- virtual void func = 0;
- virtual void func() = 0;
- virtual void func(){0};
- void func() = 0;
Answer: 2
virtual void func() = 0; is the correct declaration.
Q) In a class, pure virtual functions in C++ is used
- To create an interface
- To make a class abstract
- To force derived class to implement the pure virtual function
- All the above
Answer: 4
All are correct. Recommended to read abstract class in c++ with example that uses pure virtual function.
Q) Which public member of a base class cannot be inherited?
- Constructor
- Destructor
- Both A & B
- Only B
Answer: 3
In C++ constructor and destructor both cannot be inherited to child class.
Q) How many VPTR is created internally for a base class and a derived class
- 0
- 1
- 2
- 3
Answer: 2
Q) Number of virtual table created for a base and a derived class is
- 0
- 1
- 2
- 3
Answer: 3