Skip to main content

Object Oriented Programming MCQs with Answers

Practice important Object Oriented Programming MCQs with answers and explanations.

Chapter: 11
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
Correct Answer: B
Chapter: 11
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) {}
Correct Answer: A
Chapter: 11
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
Correct Answer: B
Chapter: 11
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
Correct Answer: B
Chapter: 11
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
Correct Answer: B
Chapter: 11
Q166:
Which keyword is used to declare a static data member in a class?
A. const
B. static
C. private
D. protected
Correct Answer: B
Chapter: 11
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
Correct Answer: B
Chapter: 11
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
Correct Answer: B
Chapter: 11
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
Correct Answer: A
Chapter: 11
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
Correct Answer: C
Chapter: 11
Q171:
The Student class member const int rollNo cannot be modified in which part of the class?
A. Constructor
B. Member functions
C. Static methods
D. Initializer list
Correct Answer: B
Chapter: 11
Q172:
In the Student class example, how is the static int noOfStudents variable initialized?
A. Inside the class definition
B. At the time of definition outside the class
C. In the constructor
D. Through a member function
Correct Answer: B
Chapter: 11
Q173:
What is a primary benefit of using constant member functions?
A. They allow modification of object state
B. They prevent modification of object state
C. They increase execution speed
D. They reduce memory usage
Correct Answer: B
Chapter: 12
Q174:
What is a static data member in a class?
A. A variable specific to each object
B. A variable shared by all instances of the class
C. A variable only accessible within member functions
D. A global variable
Correct Answer: B
Chapter: 12
Q175:
How are static data members initialized in C++?
A. Inside the class definition
B. Outside the class definition
C. In the constructor
D. Through a member function
Correct Answer: B
Chapter: 12
Q176:
What is the main benefit of using static data members?
A. They belong to each object
B. They are initialized each time an object is created
C. They are shared by all instances of the class
D. They can be modified by any object
Correct Answer: C
Chapter: 12
Q177:
What happens if a static data member is not explicitly initialized?
A. It causes a compilation error
B. It is initialized to a random value
C. It is initialized to 0
D. It remains uninitialized
Correct Answer: C
Chapter: 12
Q178:
Which operator is used to access a static data member?
A. Dot operator (.)
B. Scope resolution operator (::)
C. Arrow operator (->)
D. Member access operator (.)
Correct Answer: B
Chapter: 12
Q179:
In the provided Student class example, how is the noOfStudents data member accessed?
A. Student::noOfStudents
B. aStudent.noOfStudents
C. Student.getTotalStudents()
D. aStudent.getTotalStudents()
Correct Answer: A
Chapter: 12
Q180:
What is a static member function in C++?
A. A function that operates on individual objects
B. A function that does not require an object to be invoked
C. A function that accesses non-static members
D. A function that modifies static data members
Correct Answer: B

Test Your Knowledge

Take a timed quiz on Object Oriented Programming

🚀 Start Quiz Now