Skip to content
QuiznExam

OOPS Concepts in C++ Quiz

Test your knowledge of object-oriented programming (OOP) concepts in C++, including encapsulation, inheritance, polymorphism, abstraction, classes, objects, function overloading, function overriding, virtual functions, and access specifiers.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What does OOP stand for in C++?

    • A. Object-Oriented Programming
    • B. Operational Object Processing
    • C. Organized Output Programming
    • D. Object Operation Protocol
    Show answer

    A. Object-Oriented Programming

    OOP is a programming approach that organizes software around objects containing data and related behavior.

  2. 2. Which of the following is a fundamental concept of object-oriented programming?

    • A. Compilation
    • B. Encapsulation
    • C. Linking
    • D. Preprocessing
    Show answer

    B. Encapsulation

    Encapsulation combines data and related functions into a unit and controls access to an object's internal state.

  3. 3. What is inheritance in C++?

    • A. Creating multiple objects from one function
    • B. Hiding all data members from every function
    • C. Creating a class that derives properties and behavior from another class
    • D. Converting a class into a primitive data type
    Show answer

    C. Creating a class that derives properties and behavior from another class

    Inheritance allows a derived class to reuse and extend accessible members and behavior from a base class.

  4. 4. Which OOP concept allows the same interface to represent different behaviors?

    • A. Encapsulation
    • B. Abstraction
    • C. Inheritance
    • D. Polymorphism
    Show answer

    D. Polymorphism

    Polymorphism allows the same interface or operation to produce different behavior depending on the context or object type.

  5. 5. What is abstraction in object-oriented programming?

    • A. Displaying every implementation detail to users
    • B. Hiding unnecessary implementation details and exposing essential functionality
    • C. Creating a copy of every object
    • D. Making all class members public
    Show answer

    B. Hiding unnecessary implementation details and exposing essential functionality

    Abstraction focuses on what an object does while hiding unnecessary details about how it works.

  6. 6. Which access specifier allows derived classes to access a base class member while generally preventing direct access from unrelated external code?

    • A. private
    • B. public
    • C. protected
    • D. global
    Show answer

    C. protected

    Protected members are accessible within the class and its derived classes, subject to C++ access rules.

  7. 7. Which type of inheritance allows a class to inherit from more than one base class?

    • A. Multiple inheritance
    • B. Single inheritance
    • C. Hierarchical inheritance
    • D. Multilevel inheritance
    Show answer

    A. Multiple inheritance

    Multiple inheritance allows one derived class to have two or more direct base classes.

  8. 8. What is function overloading in C++?

    • A. Defining two functions with identical signatures in the same scope
    • B. Calling a function without declaring it
    • C. Replacing a destructor with a constructor
    • D. Defining multiple functions with the same name but different parameter lists
    Show answer

    D. Defining multiple functions with the same name but different parameter lists

    Function overloading allows functions to share a name while differing in their parameter lists. Return type alone cannot distinguish overloaded functions.

  9. 9. What is function overriding in C++?

    • A. Defining a function with a different name in the same class
    • B. Providing a derived-class implementation of an inherited virtual function with a matching signature
    • C. Declaring two constructors with different parameters
    • D. Calling a function recursively
    Show answer

    B. Providing a derived-class implementation of an inherited virtual function with a matching signature

    Overriding lets a derived class provide its own implementation of a base class virtual function. The override specifier can help the compiler verify the declaration.

  10. 10. Which keyword enables runtime polymorphism through virtual function calls in C++?

    • A. static
    • B. friend
    • C. virtual
    • D. inline
    Show answer

    C. virtual

    The virtual keyword enables dynamic dispatch when a virtual function is called through a base-class pointer or reference.

  11. 11. What is the purpose of a pure virtual function in C++?

    • A. To declare an interface-like function that can make a class abstract
    • B. To prevent a function from being inherited
    • C. To create a global variable
    • D. To automatically allocate memory for an object
    Show answer

    A. To declare an interface-like function that can make a class abstract

    A pure virtual function is declared using = 0. A class with at least one pure virtual function is abstract and cannot be instantiated directly.

  12. 12. Which statement about constructors in C++ is correct?

    • A. Constructors must return int
    • B. Constructors are called only when a program terminates
    • C. Constructors must always be virtual
    • D. Constructors initialize objects and have no declared return type
    Show answer

    D. Constructors initialize objects and have no declared return type

    Constructors are special member functions used during object initialization. They have the same name as the class and declare no return type.

  13. 13. What is the main purpose of a virtual destructor in a C++ base class?

    • A. To prevent derived classes from being created
    • B. To ensure proper destruction when deleting a derived object through a base-class pointer
    • C. To make every data member static
    • D. To allow constructors to return values
    Show answer

    B. To ensure proper destruction when deleting a derived object through a base-class pointer

    A virtual base-class destructor ensures that deleting a derived object through a base-class pointer invokes the appropriate derived and base destructors.

  14. 14. Which OOP principle is most directly supported by making data members private and providing public getter and setter functions?

    • A. Multiple inheritance
    • B. Function recursion
    • C. Encapsulation
    • D. Operator precedence
    Show answer

    C. Encapsulation

    Private data and controlled public access help protect an object's internal state and enforce its rules.

  15. 15. Which statement best describes compile-time polymorphism in C++?

    • A. It can be achieved through function overloading and operator overloading
    • B. It requires every function to be virtual
    • C. It occurs only when deleting objects through base pointers
    • D. It is the same as runtime polymorphism using virtual functions
    Show answer

    A. It can be achieved through function overloading and operator overloading

    Compile-time polymorphism includes mechanisms such as function and operator overloading, where the appropriate operation is selected during compilation.