MyInternships.in

OOPs Concepts — Questions and Answers

Object-oriented programming in C++ rests on four pillars — encapsulation, abstraction, inheritance and polymorphism — and interviewers test whether you can distinguish them with an example rather than recite the list. The C++-specific depth comes from compile-time versus run-time polymorphism, virtual functions and the vtable, and why a base class destructor must be virtual.

8 solved questionsC++ ProgrammingFree · no signup

OOPs Concepts— Concepts, Formulas & Shortcuts

  • Encapsulation: bundling data and the methods operating on it, with access controlled by private/protected/public.
  • Abstraction: exposing what an object does while hiding how — achieved with abstract classes and pure virtual functions.
  • Inheritance: deriving a class from another to reuse and extend behaviour.
  • Polymorphism: compile-time (function/operator overloading) versus run-time (virtual functions).
  • A pure virtual function (virtual void f() = 0;) makes the class abstract — it cannot be instantiated.
  • Deleting a derived object through a base pointer requires a virtual destructor, or the derived destructor never runs.

OOPs Concepts Practice Questions with Answers

Attempt each question first, then open the explanation. All 8 questions below are free to read and require no signup.

  1. Q1.Which of the following is NOT one of the four pillars of OOP?

    Easy
    • AEncapsulation
    • BInheritance
    • CCompilation
    • DPolymorphism
    +Show Answer & Explanation

    Answer: C. Compilation

    Explanation: The four pillars are encapsulation, abstraction, inheritance and polymorphism. Compilation is a build step, not an OOP concept.

    OOPs Concepts question 1 of 8
  2. Q2.Run-time polymorphism in C++ is achieved through:

    Moderate
    • AFunction overloading
    • BOperator overloading
    • CVirtual functions
    • DTemplates
    +Show Answer & Explanation

    Answer: C. Virtual functions

    Explanation: Virtual functions are dispatched via the vtable at run time. Overloading and templates are resolved at compile time.

    OOPs Concepts question 2 of 8
  3. Q3.A class containing at least one pure virtual function is called:

    Easy
    • AA friend class
    • BAn abstract class
    • CA static class
    • DA sealed class
    +Show Answer & Explanation

    Answer: B. An abstract class

    Explanation: A pure virtual function makes the class abstract, so it cannot be instantiated and must be inherited from.

    OOPs Concepts question 3 of 8
  4. Q4.What happens if a base class destructor is not declared virtual and a derived object is deleted through a base pointer?

    Difficult
    • ACompilation error
    • BOnly the base destructor runs, leaking derived resources
    • CBoth destructors run normally
    • DThe program always crashes
    +Show Answer & Explanation

    Answer: B. Only the base destructor runs, leaking derived resources

    Explanation: Without a virtual destructor the call is statically bound to the base destructor, so the derived class part is never cleaned up.

    OOPs Concepts question 4 of 8
  5. Q5.Which access specifier makes members accessible to derived classes but not to outside code?

    Easy
    • Aprivate
    • Bprotected
    • Cpublic
    • Dfriend
    +Show Answer & Explanation

    Answer: B. protected

    Explanation: protected members are visible inside the class and to its derived classes, but not to unrelated external code.

    OOPs Concepts question 5 of 8
  6. Q6.A friend function in C++:

    Moderate
    • AIs a member of the class
    • BCan access private members without being a member
    • CIs inherited by derived classes
    • DMust be declared public
    +Show Answer & Explanation

    Answer: B. Can access private members without being a member

    Explanation: A friend is a non-member function granted access to private and protected members. Friendship is neither inherited nor reciprocal.

    OOPs Concepts question 6 of 8
  7. Q7.Which feature allows the same operator to behave differently for user-defined types?

    Easy
    • AInheritance
    • BOperator overloading
    • CEncapsulation
    • DAbstraction
    +Show Answer & Explanation

    Answer: B. Operator overloading

    Explanation: Operator overloading gives operators like + or << a custom meaning for a class — a form of compile-time polymorphism.

    OOPs Concepts question 7 of 8
  8. Q8.In multiple inheritance, the ambiguity when a class inherits the same base twice is solved by:

    Difficult
    • AVirtual base classes
    • BFriend functions
    • CStatic members
    • DTemplates
    +Show Answer & Explanation

    Answer: A. Virtual base classes

    Explanation: Declaring the common base virtual ensures only one shared sub-object exists, resolving the diamond problem.

    OOPs Concepts question 8 of 8

OOPs Concepts — Frequently Asked Questions

What is the difference between overloading and overriding?+

Overloading means several functions share a name but differ in parameters, resolved at compile time. Overriding means a derived class redefines a base class virtual function with the same signature, resolved at run time through the vtable.

Why should a base class destructor be virtual?+

So that deleting a derived object through a base class pointer calls the derived destructor first. Without it the derived part is never destroyed, leaking resources.

Cleared the aptitude round? Now grab the role.

Preparation only pays off when you apply. Thousands of internships and fresher jobs across India are live on MyInternships.in right now — free to apply, no consultancy fees.