Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q331: What is the result of using the explicit keyword in a constructor?
- A: The constructor becomes private
- B: The constructor cannot be overloaded
- C: Automatic type conversion is disabled
- D: The constructor must be static
View Answer
C
Q332: What does the following code do? String s(‘A’); cout << s.GetStringPtr();
- A: Outputs "A"
- B: Outputs "65"
- C: Outputs "A65"
- D: Causes a runtime error
View Answer
B
Q333: Which of the following will cause an error due to the use of the explicit keyword in the constructor?
- A: String s = 65;
- B: String s; s = String(101);
- C: String s; s = ‘A’;
- D: String s; s = (String)101;
View Answer
C
Q334: How does the compiler differentiate between pre-increment and post-increment in operator overloading?
- A: By the number of parameters
- B: By the return type
- C: By the dummy parameter
- D: By the function name
View Answer
C
Q335: In the following code, what is returned by the operator++(int) function? Complex h1; h1++;
- A: The original value of h1
- B: The incremented value of h1
- C: A temporary object
- D: A null object
View Answer
C
Q336: Which type of function is typically used for user-defined type conversion from the current type to another type?
- A: Constructor
- B: Destructor
- C: Copy constructor
- D: Operator function
View Answer
D
Q337: Which keyword is used to prevent implicit type conversions in C++?
- A: const
- B: virtual
- C: explicit
- D: static
View Answer
C
Q338: The following code causes a type conversion. What is being converted? String s = 345;
- A: int to String
- B: String to char *
- C: String to int
- D: char * to String
View Answer
A
Q339: What is the output of the following code? String s("1234"); cout << (char *)s;
- A: "1234"
- B: 1234
- C: Junk value
- D: 0
View Answer
A
Q340: What will be the result of using explicit keyword with a constructor when a string is initialized as String s = ‘A’;?
- A: Causes a compile-time error
- B: Causes a runtime error
- C: Initializes with "A"
- D: Initializes with "65"
View Answer
A