Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Multiple Choice Questions

Q161: Which of the following correctly initializes a constant data member in C++?
  • A: Using assignment in constructor
  • B: Using member initializer list
  • C: Using a setter function
  • D: Using a static variable
View Answer
B

Q162: In the provided Student class, what is the correct way to initialize const int rollNo?
  • A: Student(int aRollNo) : rollNo(aRollNo) {}
  • B: Student(int aRollNo) { rollNo = aRollNo; }
  • C: Student() { rollNo = 0; }
  • D: Student() : rollNo(0) {}
View Answer
A

Q163: What is the result of initializing a static variable inside a function?
  • A: It gets reinitialized with each function call
  • B: It is initialized once and retains its value
  • C: It does not get initialized
  • D: It causes a compilation error
View Answer
B

Q164: What type of functions can be accessed by constant objects?
  • A: Non-const member functions
  • B: Const member functions
  • C: Static member functions
  • D: Friend functions
View Answer
B

Q165: Static data members in a class are initialized in which scope?
  • A: Inside the class definition
  • B: Outside the class definition
  • C: Inside a function
  • D: In the constructor
View Answer
B

Q166: Which keyword is used to declare a static data member in a class?
  • A: const
  • B: static
  • C: private
  • D: protected
View Answer
B

Q167: In the Student class example, int getRollNo() const { return rollNo; } can be used with which type of object?
  • A: Non-const objects
  • B: Const objects
  • C: Static objects
  • D: Friend objects
View Answer
B

Q168: The order of initialization of data members in a class is determined by which factor?
  • A: Order in the constructor initializer list
  • B: Order in the class definition
  • C: Order in the main function
  • D: Order in the member functions
View Answer
B

Q169: In the provided Student class, what happens if a static data member is not explicitly initialized?
  • A: It is initialized to a default value of 0
  • B: It is initialized to a random value
  • C: It causes a compilation error
  • D: It remains uninitialized
View Answer
A

Q170: How are static data members defined in C++?
  • A: Inside the class definition
  • B: Inside the member initializer list
  • C: Outside the class definition
  • D: Inside the constructor
View Answer
C

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now