C++ OOPs Concepts Test 4

    Question 1C++ OOPS - Constructors

    What is true about constructors in C++?

    Question 2C++ OOPS - Destructor Characteristics

    Which of the following is true about destructors in C++?

    Question 3C++ OOPS - Getter Method

    Which is the correct way to write a getter for salary (private) in class Employee?

    Question 4C++ OOPS - Virtual Inheritance

    Which keyword is used to solve the diamond problem in C++?

    Question 5C++ OOPS - Pure Virtual Function

    How do we declare a pure virtual function?

    Question 6C++ OOPS Partial Abstraction

    Can an abstract class in C++ have normal (non-virtual) functions?

    Question 7C++ OOPS Friend Function and Object Passing

    What will be the output?

    #include <iostream> using namespace std; class Number { int value; public: Number(int v) { value = v; } friend int getValue(Number n); }; int getValue(Number n) { return n.value; } int main() { Number n(42); cout << getValue(n); }

    Question 8C++ OOPS Static Function Limitation

    Which of the following is NOT allowed in static member functions?

    Question 9C++ OOPS Overloading Postfix ++

    Which is the correct function signature for overloading postfix ++?

    Question 10C++ OOPS Multiple Inheritance & V-Table

    How is V-Table affected in multiple inheritance?

    Question 11C++ OOPS - Destructor

    Which symbol is used before the class name to define a destructor?

    Question 12C++ OOPS - Destructor Naming

    Which is the correct way to define a destructor for class `Car`?

    Question 13C++ OOPS - Setter Method

    Which is the best way to define a setter for salary in class Employee?

    Question 14C++ OOPS - Constructor Call Order

    In inheritance, what is the order of constructor calls?

    Question 15C++ OOPS - Abstract Class Example

    What will be the output?

    #include<iostream> using namespace std; class Shape { public: virtual void draw() = 0; }; class Circle : public Shape { public: void draw() { cout << "Circle"; } }; int main() { Circle c; c.draw(); }

    Question 16C++ OOPS Pure Virtual Function Without Definition

    Which of the following is true about pure virtual functions?

    Question 17C++ OOPS Friend Function vs Member Function

    Which of the following is true?

    Question 18C++ OOPS Static Variable Behavior

    What will be the output?

    #include <iostream> using namespace std; class Demo { static int x; public: Demo() { x++; } ~Demo() { x--; } static int getX() { return x; } }; int Demo::x = 0; int main() { Demo d1, d2; cout << Demo::getX(); }

    Question 19C++ OOPS Relational Operator Overloading

    What will be the output?

    #include <iostream> using namespace std; class Box { int volume; public: Box(int v) : volume(v) {} bool operator>(Box b) { return volume > b.volume; } }; int main() { Box b1(10), b2(20); cout << (b1 > b2); }

    Question 20C++ OOPS Virtual Destructor Importance

    Why should destructors be declared virtual in base classes?