Object Oriented Programming MCQs with Answers
Practice important Object Oriented Programming MCQs with answers and explanations.
Multiple Choice Questions
Q231: In the `Student` class example, which class is used as a data member to represent the student's name?
- A: String
- B: Char
- C: Date
- D: Integer
View Answer
A
Q232: The `Student` class uses composition to include which of the following classes?
- A: String
- B: Date
- C: Chair
- D: Both A and B
View Answer
D
Q233: What is the output of the constructor call `Student aStudent("Fakhir", 899, 3.1);` in terms of constructor messages?
- A: Only "Constructor::Student"
- B: Constructor::String followed by "Constructor::Student"
- C: Destructor::Student followed by "Destructor::String"
- D: None of the above
View Answer
B
Q234: What does the `Student` class destructor do?
- A: Deletes the student object
- B: Deletes the name object
- C: Deletes the date object
- D: Deletes both name and date objects
View Answer
B
Q235: In aggregation, objects can exist _______ each other.
- A: dependently
- B: independently
- C: permanently
- D: temporarily
View Answer
B
Q236: What is the main difference between composition and aggregation?
- A: Lifetime dependency of sub-objects
- B: Memory usage
- C: Execution speed
- D: Compiler support
View Answer
A
Q237: In the `Room` class example, what does the `AddChair` method do?
- A: Adds a chair to the room's array of chairs
- B: Removes a chair from the room
- C: Checks if a chair can be folded
- D: Returns a chair from the room
View Answer
A
Q238: Which of the following best describes a friend function?
- A: A non-member function that can access private members of a class
- B: A member function of a class
- C: A constructor function
- D: A destructor function
View Answer
A
Q239: The `DoSomething` function is made a friend of class `X`. What can this function now do?
- A: Access private members of `X`
- B: Access public members of `X`
- C: Modify the class `X` definition
- D: Instantiate objects of class `X`
View Answer
A
Q240: What keyword is used to declare a friend function in a class?
- A: friend
- B: public
- C: private
- D: protected
View Answer
A