Any2Quiz
Computer Science / Languages / C++

OOP Quiz - Languages C++

Free practice quiz: OOP (Languages C++). 16 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

Play all 16 questions free

Sample questions

  1. Which of the following is NOT a fundamental principle of Object-Oriented Programming (OOP)?

    1. Encapsulation
    2. Inheritance
    3. Polymorphism
    4. Procedural Abstraction
    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.

  2. What is the primary purpose of inheritance in C++ OOP?

    1. To restrict access to member variables.
    2. To create new classes that reuse, extend, and modify the behavior defined in other classes.
    3. To define constant values within a class.
    4. To ensure that a class can only have one instance.
    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.

  3. What is a pure virtual function in C++?

    1. A virtual function that has no body.
    2. A virtual function that can only be called from the base class.
    3. A virtual function that is automatically overridden by derived classes.
    4. A virtual function that returns a void type.
    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.

  4. 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`?

    1. Public
    2. Protected
    3. Private
    4. Inaccessible
    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.

  5. What is the purpose of the `this` pointer in C++?

    1. To point to the next object in a collection.
    2. To refer to the current object within a member function.
    3. To point to the base class.
    4. To point to the global scope.
    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.

Take the full quiz

More quizzes

Browse all C++ quizzes