Q) Features not available in C++ object oriented programming is
- Virtual destructor
- Virtual constructor
- Virtual function
- All
Answer: 2
There is no concept of virtual constructor available in C++. However, virtual destructor is available in C++ language to maintain the destructor call from derived to base class. In polymorphic classes, if we don’t use virtual destructor in base class then the derived class destructor will not be called that may cause resource leaks.
Recommended to read why there is no virtual constructor in C++ language and a complete details of virtual destructor with example. It’s uses and how and when resources can leak etc.
Q) IS A relationship in C++ is
- Inheritance
- Encapsulation
- Composition
- None
Answer: 1
Q) If you want to write multiple functions in a class with same name, then what C++ feature will you use?
- Function overriding
- Encapsulation
- Function overloading
- None
Answer: 3
Compile time polymorphism feature is used i.e. function overloading in C++. Function overloading means, in a class, multiple functions with same name can be written with different signatures, return types etc.
Q) Polymorphism types is/are
- Compile time
- Run time
- Both
- None
Answer: 3
Two types of Polymorphism are available in C++ object oriented programming i.e. compile time and run time polymorphism. Also, known as early binding and late binding respectively.
Compiler time polymorphism features in C++ language are function overloading, constructor and operator overloading etc. and run time polymorphism is function overriding in inheritance relationship.
Q) If I want to have common functions in a class and want to defer implementations of some other functions to derived classes, then we need to use
- An interface
- An abstract class
- A friend class
- A static class
Answer: 2
In C++ object oriented programming, abstract class is used for the same, in which we have common or say generalized function in abstract base class and also may have pure virtual function in this class that forces derived classes to implement it.
Read in detail about an abstract class oops concept with example in C++ and also, pure virtual function used to create an abstract class and interface in C++ language.