OOP Quiz - Languages C++
Free practice quiz: OOP (Languages C++). 16 multiple-choice questions with answers and explanations. Play online, no sign-up needed.
This Languages C++ practice quiz has 16 multiple-choice questions on OOP, and 16 of them come with an explanation. Try the 5 sample questions below (tap an option to check yourself), then play the full quiz online. No sign-up needed.
Start quiz: 16 questions, freeSample questions
Which of the following is NOT a fundamental principle of Object-Oriented Programming (OOP)?
Show answer
Answer: D. Procedural Abstraction
Encapsulation, Inheritance, and Polymorphism are core principles of OOP. Procedural Abstraction is a concept related to procedural programming, not OOP directly.
What is the primary purpose of inheritance in C++ OOP?
Show answer
Answer: B. To create new classes that reuse, extend, and modify the behavior defined in other classes.
Inheritance allows a new class (derived class) to inherit properties and behaviors from an existing class (base class), promoting code reusability and establishing an 'is-a' relationship.
What is a pure virtual function in C++?
Show answer
Answer: A. A virtual function that has no body.
A pure virtual function is declared by appending `= 0` to its declaration. It compels derived classes to provide an implementation for this function, making the base class abstract.
Consider a class `A` with a protected member `y`. If class `B` inherits privately from `A`, what is the access specifier of `y` in class `B`?
Show answer
Answer: C. Private
In private inheritance, protected members of the base class become private members of the derived class. Public members of the base class also become private members of the derived class.
What is the purpose of the `this` pointer in C++?
Show answer
Answer: B. To refer to the current object within a member function.
The `this` pointer is a keyword available in C++ member functions. It holds the memory address of the object for which the member function is currently being invoked.
More questions in this quiz
Answers and explanations are in the full quiz.
- What does encapsulation in C++ achieve?
- Consider a base class `Shape` and derived classes `Circle` and `Rectangle`. If `Shape` has a virtual function `draw()`, what is polymorphism in this context?
- Which keyword is used to define a class in C++?
- What is an abstract class in C++?
- What is the purpose of the `virtual` keyword when applied to a member function in C++?
- Consider a class `A` with a public member `x`. If class `B` inherits publicly from `A`, what is the access specifier of `x` in class `B`?
- What is a destructor in C++?
- Which of the following correctly declares a constructor for a class named `MyClass`?
- Which access specifier in C++ makes members accessible only within the class itself and by derived classes?
- What is method overloading in OOP?
- What is method overriding in OOP?