OOPs QUIZ
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
MCQ 01
Which of the following operators is used to access members of a class in C++? Question 1 A)-> B). C) :: D) [ ]
A) -> Which of the following operators is used to access members of a class in C++? Question 1
1. int main() 2. void main() 3. None 4. Both 1 and 2 Which of the following is the correct implementation / use of main() function? Question 2
1. int main() Which of the following operators is used to access members of a class in C++? Question 2
1. The program has encountered an error. 2. The program has executed successfully. 3. It has no specific meaning. 4. It causes the program to terminate immediately. What does return 0; signify in the main function? Question 3
The program has executed successfully. What does return 0; signify in the main function? Question 3
1. The main function can only create instances of classes. 2. The main function cannot use class methods. 3. The main function can access static members of classes directly. 4. The main function must be defined within a class. Which of the following statements is true regarding the use of the main function in object-oriented programming? Question 4
The main function can access static members of classes directly Which of the following statements is true regarding the use of the main function in object-oriented programming? Question 4
A. The function continues to execute any remaining statements after the return. B. The function exits immediately, and control is passed back to the calling function. C. The function returns control to the main function. D. The function throws an exception. In C++, what happens when a return statement is encountered in a function? Question 5
The function exits immediately, and control is passed back to the calling function. In C++, what happens when a return statement is encountered in a function? Question 5
A. The return statement can be used to return a value from a function. B. A void function can have a return statement without any value. C. If a function returns void, it cannot have a return statement. D. When a return statement is executed, the function terminates immediately. Which of the following statements about the return statement in C++ is false? Question 6
If a function returns void, it cannot have a return statement. Which of the following statements about the return statement in C++ is false? Question 6
A) Only the constructor B) Only the destructor C) Both constructor and destructor D) Copy constructor and assignment operator If a class has dynamically allocated memory, which of the following should be implemented? Question 6
Copy constructor and assignment operator Which of the following statements about the return statement in C++ is false? Question 6
A) All statements are Valid. B) A derived class can override the constructor of a virtually inherited class. Which of the following statements is NOT valid in the context of virtual inheritance in C++? Question 7 C) A virtually inherited base class's constructor is called only once, regardless of how many derived classes inherit it. D) In virtual inheritance, the most derived class is responsible for initializing the virtually inherited base class.
A derived class can override the constructor of a virtually inherited class. Which of the following statements is NOT valid in the context of virtual inheritance in C++? Question 7
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
True False 02
Question 1 Friend functions can be inherited by derived classes. TRUE FALSE
Question 1 Friend functions can be inherited by derived classes. TRUE FALSE
Question 2 The scope of a variable declared inside a function in C++ is Class scope. TRUE FALSE
Question 2 The scope of a variable declared inside a function in C++ is Class scope. TRUE FALSE
Question 3 The size of int data type is always 4 bytes, irrespective of the system architecture. TRUE FALSE
Question 3 The size of int data type is always 4 bytes, irrespective of the system architecture. TRUE FALSE
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
Fill in the Blanks 03
Question 1 In a class, a static member function can only access ______ data members of the class, because it does not have access to the ______ pointer.
Question 1 In a class, a static member function can only access ______ data members of the class, because it does not have access to the ______ pointer. 1. static 2. this
Question 2 To call a static member function multiply from a class named MathOperations, you can write MathOperations::multiply(4, 5);. This syntax is possible because multiply is associated with the ____ itself, not with any specific ____.
Question 2 To call a static member function multiply from a class named MathOperations, you can write MathOperations::multiply(4, 5);. This syntax is possible because multiply is associated with the ____ itself, not with any specific ____. 1. Class 2. Object
Question 3 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
Question 3 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -) ::
Question 4 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
Question 4 In C++, the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -) ::
Question 5 When overloading an operator as a member function, the left-hand operand is always __________.
Question 5 When overloading an operator as a member function, the left-hand operand is always __________. this
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
Assertion Reasoning 04
Static member functions cannot be virtual. Static member functions are associated with the class, not with specific instances of the class. ASSERTION REASON A false, R true A true, R false Both False Both True Question 1
Static member functions cannot be virtual. Static member functions are associated with the class, not with specific instances of the class. ASSERTION REASON A false, R true A true, R false Both False Both True Question 1
Destructors can have return types in C++. Destructors must return void because they are automatically called by the system and are not meant to return values. ASSERTION REASON Both True A false, R true A true, R false Both False Question 2
Destructors can have return types in C++. Destructors must return void because they are automatically called by the system and are not meant to return values. ASSERTION REASON Both True A false, R true A true, R false Both False Question 2
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
MCQ True False Questions Fill in the Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
Output Finding 05
55 int x = 5; x = x+++++x; Find the output by analyzing the code. Question 1
56 int x = 5; x = x+++++x; Find the output by analyzing the code. Answer: Undefined behavior Question 1
57 Find the output by analyzing the code. class Test { public: int x; Test(int value) : x(value) { cout << "Constructor called for x = " << x << endl; } ~Test() { cout << "Destructor called for x = " << x << endl; } }; int main() { Test t1(10); { Test t2(20); } cout << "End of main" << endl; return 0; } Question 2
58 Find the output by analyzing the code. class Test { public: int x; Test(int value) : x(value) { cout << "Constructor called for x = " << x << endl; } ~Test() { cout << "Destructor called for x = " << x << endl; } }; int main() { Test t1(10); { Test t2(20); } cout << "End of main" << endl; return 0; } Ans: Constructor called for x = 10 Constructor called for x = 20 Destructor called for x = 20 End of main Destructor called for x = 10 Question 2
59 Find the output by analyzing the code. class MyClass { int* ptr; public: MyClass(int size) { ptr = new int[size]; // Dynamically allocate memory cout << "Memory allocated for " << size << " integers." << endl; } ~MyClass() { delete[] ptr; // Deallocate memory cout << "Memory deallocated." << endl; } }; int main() { MyClass obj(5); // Dynamically allocate memory for 5 integers return 0; } Question 3
60 Find the output by analyzing the code. class MyClass { int* ptr; public: MyClass(int size) { ptr = new int[size]; // Dynamically allocate memory cout << "Memory allocated for " << size << " integers." << endl; } ~MyClass() { delete[] ptr; // Deallocate memory cout << "Memory deallocated." << endl; } }; int main() { MyClass obj(5); // Dynamically allocate memory for 5 integers return 0; } Answer: The output will be: Memory allocated for 5 integers. Memory deallocated. Question 3
61 Find the output by analyzing the code. class Complex { public: int real, imag; Complex(int r, int i) : real(r), imag(i) {} Complex operator*(const Complex& c) { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } void display() { cout << real << "+" << imag << "i "; } }; int main() { Complex c1(2, 3), c2(4, 5); Complex c3 = c1 * c2; c3.display(); return 0; } Question 4
62 Find the output by analyzing the code. class Complex { public: int real, imag; Complex(int r, int i) : real(r), imag(i) {} Complex operator*(const Complex& c) { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } void display() { cout << real << "+" << imag << "i "; } }; int main() { Complex c1(2, 3), c2(4, 5); Complex c3 = c1 * c2; c3.display(); return 0; } Answer: -7+22i Question 4
END OF QUIZ
Thank you.

Object Oriented Programming using C++ / C Plus Plus QUIZ

  • 3.
  • 4.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 5.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 6.
  • 7.
    Which of thefollowing operators is used to access members of a class in C++? Question 1 A)-> B). C) :: D) [ ]
  • 8.
    A) -> Which ofthe following operators is used to access members of a class in C++? Question 1
  • 9.
    1. int main() 2.void main() 3. None 4. Both 1 and 2 Which of the following is the correct implementation / use of main() function? Question 2
  • 10.
    1. int main() Whichof the following operators is used to access members of a class in C++? Question 2
  • 11.
    1. The programhas encountered an error. 2. The program has executed successfully. 3. It has no specific meaning. 4. It causes the program to terminate immediately. What does return 0; signify in the main function? Question 3
  • 12.
    The program hasexecuted successfully. What does return 0; signify in the main function? Question 3
  • 13.
    1. The mainfunction can only create instances of classes. 2. The main function cannot use class methods. 3. The main function can access static members of classes directly. 4. The main function must be defined within a class. Which of the following statements is true regarding the use of the main function in object-oriented programming? Question 4
  • 14.
    The main functioncan access static members of classes directly Which of the following statements is true regarding the use of the main function in object-oriented programming? Question 4
  • 15.
    A. The functioncontinues to execute any remaining statements after the return. B. The function exits immediately, and control is passed back to the calling function. C. The function returns control to the main function. D. The function throws an exception. In C++, what happens when a return statement is encountered in a function? Question 5
  • 16.
    The function exitsimmediately, and control is passed back to the calling function. In C++, what happens when a return statement is encountered in a function? Question 5
  • 17.
    A. The returnstatement can be used to return a value from a function. B. A void function can have a return statement without any value. C. If a function returns void, it cannot have a return statement. D. When a return statement is executed, the function terminates immediately. Which of the following statements about the return statement in C++ is false? Question 6
  • 18.
    If a functionreturns void, it cannot have a return statement. Which of the following statements about the return statement in C++ is false? Question 6
  • 19.
    A) Only theconstructor B) Only the destructor C) Both constructor and destructor D) Copy constructor and assignment operator If a class has dynamically allocated memory, which of the following should be implemented? Question 6
  • 20.
    Copy constructor and assignmentoperator Which of the following statements about the return statement in C++ is false? Question 6
  • 21.
    A) All statementsare Valid. B) A derived class can override the constructor of a virtually inherited class. Which of the following statements is NOT valid in the context of virtual inheritance in C++? Question 7 C) A virtually inherited base class's constructor is called only once, regardless of how many derived classes inherit it. D) In virtual inheritance, the most derived class is responsible for initializing the virtually inherited base class.
  • 22.
    A derived classcan override the constructor of a virtually inherited class. Which of the following statements is NOT valid in the context of virtual inheritance in C++? Question 7
  • 23.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 24.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 25.
  • 26.
    Question 1 Friend functionscan be inherited by derived classes. TRUE FALSE
  • 27.
    Question 1 Friend functionscan be inherited by derived classes. TRUE FALSE
  • 28.
    Question 2 The scopeof a variable declared inside a function in C++ is Class scope. TRUE FALSE
  • 29.
    Question 2 The scopeof a variable declared inside a function in C++ is Class scope. TRUE FALSE
  • 30.
    Question 3 The sizeof int data type is always 4 bytes, irrespective of the system architecture. TRUE FALSE
  • 31.
    Question 3 The sizeof int data type is always 4 bytes, irrespective of the system architecture. TRUE FALSE
  • 32.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 33.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 34.
  • 35.
    Question 1 In aclass, a static member function can only access ______ data members of the class, because it does not have access to the ______ pointer.
  • 36.
    Question 1 In aclass, a static member function can only access ______ data members of the class, because it does not have access to the ______ pointer. 1. static 2. this
  • 37.
    Question 2 To calla static member function multiply from a class named MathOperations, you can write MathOperations::multiply(4, 5);. This syntax is possible because multiply is associated with the ____ itself, not with any specific ____.
  • 38.
    Question 2 To calla static member function multiply from a class named MathOperations, you can write MathOperations::multiply(4, 5);. This syntax is possible because multiply is associated with the ____ itself, not with any specific ____. 1. Class 2. Object
  • 39.
    Question 3 In C++,the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
  • 40.
    Question 3 In C++,the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -) ::
  • 41.
    Question 4 In C++,the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -)
  • 42.
    Question 4 In C++,the operator ___ cannot be overloaded. (Choose one: ::, ++, +, -) ::
  • 43.
    Question 5 When overloadingan operator as a member function, the left-hand operand is always __________.
  • 44.
    Question 5 When overloadingan operator as a member function, the left-hand operand is always __________. this
  • 45.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 46.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 47.
  • 48.
    Static member functionscannot be virtual. Static member functions are associated with the class, not with specific instances of the class. ASSERTION REASON A false, R true A true, R false Both False Both True Question 1
  • 49.
    Static member functionscannot be virtual. Static member functions are associated with the class, not with specific instances of the class. ASSERTION REASON A false, R true A true, R false Both False Both True Question 1
  • 50.
    Destructors can havereturn types in C++. Destructors must return void because they are automatically called by the system and are not meant to return values. ASSERTION REASON Both True A false, R true A true, R false Both False Question 2
  • 51.
    Destructors can havereturn types in C++. Destructors must return void because they are automatically called by the system and are not meant to return values. ASSERTION REASON Both True A false, R true A true, R false Both False Question 2
  • 52.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 53.
    MCQ True False Questions Fill inthe Blanks Assertion Reasoning 01 02 04 03 Output Finding 05
  • 54.
  • 55.
    55 int x =5; x = x+++++x; Find the output by analyzing the code. Question 1
  • 56.
    56 int x =5; x = x+++++x; Find the output by analyzing the code. Answer: Undefined behavior Question 1
  • 57.
    57 Find the outputby analyzing the code. class Test { public: int x; Test(int value) : x(value) { cout << "Constructor called for x = " << x << endl; } ~Test() { cout << "Destructor called for x = " << x << endl; } }; int main() { Test t1(10); { Test t2(20); } cout << "End of main" << endl; return 0; } Question 2
  • 58.
    58 Find the outputby analyzing the code. class Test { public: int x; Test(int value) : x(value) { cout << "Constructor called for x = " << x << endl; } ~Test() { cout << "Destructor called for x = " << x << endl; } }; int main() { Test t1(10); { Test t2(20); } cout << "End of main" << endl; return 0; } Ans: Constructor called for x = 10 Constructor called for x = 20 Destructor called for x = 20 End of main Destructor called for x = 10 Question 2
  • 59.
    59 Find the outputby analyzing the code. class MyClass { int* ptr; public: MyClass(int size) { ptr = new int[size]; // Dynamically allocate memory cout << "Memory allocated for " << size << " integers." << endl; } ~MyClass() { delete[] ptr; // Deallocate memory cout << "Memory deallocated." << endl; } }; int main() { MyClass obj(5); // Dynamically allocate memory for 5 integers return 0; } Question 3
  • 60.
    60 Find the outputby analyzing the code. class MyClass { int* ptr; public: MyClass(int size) { ptr = new int[size]; // Dynamically allocate memory cout << "Memory allocated for " << size << " integers." << endl; } ~MyClass() { delete[] ptr; // Deallocate memory cout << "Memory deallocated." << endl; } }; int main() { MyClass obj(5); // Dynamically allocate memory for 5 integers return 0; } Answer: The output will be: Memory allocated for 5 integers. Memory deallocated. Question 3
  • 61.
    61 Find the outputby analyzing the code. class Complex { public: int real, imag; Complex(int r, int i) : real(r), imag(i) {} Complex operator*(const Complex& c) { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } void display() { cout << real << "+" << imag << "i "; } }; int main() { Complex c1(2, 3), c2(4, 5); Complex c3 = c1 * c2; c3.display(); return 0; } Question 4
  • 62.
    62 Find the outputby analyzing the code. class Complex { public: int real, imag; Complex(int r, int i) : real(r), imag(i) {} Complex operator*(const Complex& c) { return Complex(real * c.real - imag * c.imag, real * c.imag + imag * c.real); } void display() { cout << real << "+" << imag << "i "; } }; int main() { Complex c1(2, 3), c2(4, 5); Complex c3 = c1 * c2; c3.display(); return 0; } Answer: -7+22i Question 4
  • 63.
  • 64.