Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 19
Q301:
To display a complex number using the << operator, the output will be in the format:
A. (real, img)
B. real + img
C. img, real
D. real - img
Correct Answer: A
Chapter: 19
Q302:
The cin object in C++ is used for ______ input.
A. Integer
B. Floating-point
C. Character
D. Console
Correct Answer: D
Chapter: 20
Q303:
Which operator is overloaded to change a single character in a string in the modified String class?
A. Subscript [] Operator
B. Stream Insertion Operator
C. Stream Extraction Operator
D. Function () Operator
Correct Answer: A
Chapter: 20
Q304:
What does the SetChar function do in the modified String class?
A. Changes the entire string
B. Changes a single character
C. Deletes the string
D. Allocates a new buffer
Correct Answer: B
Chapter: 20
Q305:
What is the purpose of the operator() in the modified String class?
A. Change the string
B. Perform a generic operation
C. Concatenate strings
D. Reverse the string
Correct Answer: B
Chapter: 20
Q306:
What will be the output of the following code: String s1("Ping"); s1.SetChar('o', 2); cout << s1.GetString();
A. Pong
B. Ping
C. Pung
D. Pang
Correct Answer: A
Chapter: 20
Q307:
In the modified String class, what does the operator() function return?
A. Integer
B. Character
C. String
D. Boolean
Correct Answer: B
Chapter: 20
Q308:
What is the advantage of using the subscript [] operator in the modified String class?
A. It is more efficient
B. It allows string concatenation
C. It prevents buffer overflow
D. It makes the code more complex
Correct Answer: A
Chapter: 20
Q309:
Which of the following operators is used for substring operations in the modified String class?
A. Subscript [] Operator
B. Stream Insertion Operator
C. Function () Operator
D. Unary Operator
Correct Answer: C
Chapter: 20
Q310:
The subscript [] operator in the modified String class must be overloaded as a ______.
A. Friend function
B. Member function
C. Static function
D. Global function
Correct Answer: B
Chapter: 20
Q311:
In the modified String class, the subscript [] operator returns a ______.
A. void
B. int
C. char &
D. float
Correct Answer: C
Chapter: 20
Q312:
What will be the output of the following code: String s("Hello World"); cout << s(1, 5);
A. Hello
B. World
C. Hell
D. o World
Correct Answer: A
Chapter: 20
Q313:
The Function () operator in the modified String class can take ______ number of parameters.
A. 1
B. 2
C. Any
D. None
Correct Answer: C
Chapter: 20
Q314:
Unary operators generally act as ______.
A. Postfix only
B. Prefix only
C. Both prefix and postfix
D. None of the above
Correct Answer: C
Chapter: 20
Q315:
In the modified String class, what is the general syntax for overloading a unary operator as a member function?
A. TYPE & operator OP();
B. TYPE & operator OP(TYPE &);
C. void operator OP(TYPE &);
D. static TYPE & operator OP();
Correct Answer: A
Chapter: 20
Q316:
Which of the following unary operators can be overloaded in a similar way as the unary ‘-’ operator?
A. +
B. ++
C. --
D. All of the above
Correct Answer: A
Chapter: 20
Q317:
The SetChar function checks if the position is valid by ensuring pos is greater than 0 and less than or equal to ______.
A. buffer length
B. string size
C. array size
D. integer value
Correct Answer: B
Chapter: 20
Q318:
What is the default access specifier for members of a class in C++?
A. Public
B. Protected
C. Private
D. Default
Correct Answer: C
Chapter: 20
Q319:
What will happen if you try to use the stream insertion operator << with a custom class without overloading it?
A. The program will compile successfully
B. A runtime error will occur
C. The program will throw a compile-time error
D. The program will print garbage values
Correct Answer: C
Chapter: 21
Q320:
What does the post-increment operator (++) do?
A. Increments and returns the new value
B. Increments and returns the old value
C. Decrements and returns the old value
D. Decrements and returns the new value
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now