Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 15
Q241:
In the provided `String` class, what does the overloaded constructor with `char *` as a parameter do?
A. Initializes the string with the given char array
B. Deletes the string
C. Initializes the string with default value
D. Returns the string
Correct Answer: A
Chapter: 15
Q242:
In the `Student` class, what is the purpose of the `GetNamePtr` method?
A. To return the pointer to the student's name
B. To set the student's name
C. To delete the student's name
D. To display the student's name
Correct Answer: A
Chapter: 15
Q243:
The `Date` class is used in the `Student` class to store which information?
A. Student's birth date
B. Student's ID
C. Student's GPA
D. Student's name
Correct Answer: A
Chapter: 16
Q244:
What is the purpose of operator overloading in C++?
A. It allows creating new operators
B. It allows using existing operators for user-defined types
C. It changes the precedence of operators
D. It creates new data types
Correct Answer: B
Chapter: 16
Q245:
Which of the following operators cannot be overloaded in C++?
A. +
B. ?
C. -
D. *
Correct Answer: B
Chapter: 16
Q246:
What is the correct way to overload the + operator as a member function in C++?
A. Complex operator +(const Complex & rhs);
B. Complex& operator +(const Complex & rhs);
C. void operator +(const Complex & rhs);
D. Complex operator +(const Complex & rhs) const;
Correct Answer: D
Chapter: 16
Q247:
In the statement `Complex c3 = c1 + c2 + c3 + c4;`, how does operator overloading affect the expression?
A. The expression is evaluated from right to left
B. The expression is evaluated from left to right
C. The expression is evaluated based on operator precedence
D. The expression cannot be evaluated if operators are overloaded
Correct Answer: B
Chapter: 16
Q248:
Which operator is used in C++ to overload operators as a non-member function?
A. operator
B. ::
C. friend
D. &
Correct Answer: A
Chapter: 16
Q249:
What is a common drawback of using a void return type for overloaded operators?
A. It is less readable and maintainable
B. Operators cannot be overloaded with void return type
C. It increases debugging time
D. It changes operator precedence
Correct Answer: A
Chapter: 16
Q250:
Fill in the blank: To overload the binary + operator for a class, the function must have at least one formal parameter of type _______.
A. primitive type
B. class type
C. int
D. type
Correct Answer: A
Chapter: 16
Q251:
What does the `operator+` member function typically return?
A. The type of the operands
B. An object of the class itself
C. A reference to the class object
D. A void pointer
Correct Answer: B
Chapter: 16
Q252:
In the context of operator overloading, which operator cannot be overloaded?
A. ::
B. +
C. -
D. *
Correct Answer: A
Chapter: 16
Q253:
Which of the following is a correct implementation of the `+` operator overload for a class?
A. Complex& Complex::operator +(const Complex & rhs){...}
B. Complex Complex::operator +(const Complex & rhs){...}
C. void Complex::operator +(const Complex & rhs){...}
D. Complex& operator +(const Complex & rhs){...}
Correct Answer: B
Chapter: 16
Q254:
Fill in the blank: In operator overloading, if the return type is `void`, the result of operations like `c1 + c2 + c3` will be stored in _______.
A. the last object
B. c1
C. c2
D. a temporary object
Correct Answer: A
Chapter: 16
Q255:
How does operator overloading impact code readability and maintenance?
A. It improves readability and maintenance
B. It decreases readability and maintenance
C. It has no effect on readability or maintenance
D. It changes code structure only
Correct Answer: B
Chapter: 16
Q256:
Fill in the blank: The precedence of an operator is _______ due to overloading.
A. affected
B. not affected
C. changed
D. irrelevant
Correct Answer: B
Chapter: 16
Q257:
What does the `operator+` function in a class typically do?
A. It adds two objects and returns the result
B. It multiplies two objects
C. It subtracts one object from another
D. It divides one object by another
Correct Answer: A
Chapter: 17
Q258:
What is the purpose of overloading the `+` operator for basic data types and user-defined classes?
A. It allows the addition of two basic data types
B. It allows addition between a user-defined class and basic data types
C. It changes the operator precedence for addition
D. It only works for basic data types
Correct Answer: B
Chapter: 17
Q259:
When overloading the `+` operator for a user-defined class, what issue arises when adding a basic data type to an object of the class?
A. The operator cannot handle basic data types
B. The operator is not defined for basic data types
C. The operator causes a type mismatch
D. The operator must be modified to handle basic data types
Correct Answer: B
Chapter: 17
Q260:
Which method allows adding a basic data type to a complex number object, as shown in the example?
A. Overloading the `+` operator for basic data types
B. Overloading the `+` operator as a friend function
C. Overloading the `+` operator in the class itself
D. Using built-in operators
Correct Answer: A

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now