C++ OOPs Interview Questions 2026: 28 Q&A With Code

What changed in 2026 drives
Mass-recruiter offer letters are flatter for 2026 batch - the 4-5 LPA ASE band has barely budged in three years while inflation eats real wages. Premium tracks (Digital, Pro, Elite, Specialist) are still where the differential lives, and they are entirely test-driven. If you are aiming higher than the default offer, the coding round is not optional pageantry - it is the entire interview.
What I'd actually study for this
- 01Two solid coding-round answers (1 medium-hard DSA each, with edge-case discussion) > five half-baked ones
- 02One real project you can defend end-to-end - file paths, design decisions, and what you would change
- 03One DBMS schema you actually built (not a textbook ER diagram), with at least 3 join-heavy queries written from memory
- 04Three behavioural STAR stories: failure recovered, conflict handled, ownership taken
Where most candidates trip up
The single biggest mistake is treating company-specific guides as primary prep and DSA as secondary. It is the opposite. Mass recruiters use the test as a filter, but premium tracks at every IT services company use coding to allocate offer band. Spend 70% of prep time on DSA + system fundamentals, 20% on company-specific patterns, 10% on HR rehearsal. Reverse that ratio and you collect the default offer.
Editorial commentary by Aditya Sharma · written for PapersAdda · not generated, not aggregated.
Last Updated: June 2026 | Level: Freshers to Mid-Level | Read Time: ~16 min
C++ object orientation goes deeper than most languages because it exposes the machinery: vtables, object layout, and manual resource management. Candidates report that virtual functions, the rule of five, and RAII are guaranteed for product-company and systems roles. This guide covers 28 C++ OOP questions with full answers and predict-the-output traps. Behaviour reflects the official cppreference documentation; confirm any object-model detail on the standard.
Pair this with C++ Programming Placement Questions and C++ STL Interview Questions 2026.
Table of Contents
- Classes and Constructors (Q1 to Q9)
- Inheritance and Virtual (Q10 to Q19)
- Resource Management (Q20 to Q25)
- Advanced (Q26 to Q28)
- Predict the Output
- Quick Revision Table
- Frequently Asked Questions
Classes and Constructors
Q1. What are the access specifiers in C++? Easy
Q2. What is the difference between struct and class in C++? Easy
Q3. What is a constructor and its types? Easy
Q4. What is a copy constructor? Medium
class Buf {
int* data;
public:
Buf(const Buf& o) { data = new int[o.size]; /* deep copy */ }
};
Q5. What is the difference between shallow and deep copy? Medium
Q6. What is an initializer list in a constructor? Medium
class P { const int x; public: P(int v) : x(v) {} };
Q7. What is a destructor and when is it called? Easy
Q8. What is the difference between a constructor and a member function? Easy
Q9. What does the explicit keyword do? Medium
Inheritance and Virtual
Q10. What are the types of inheritance in C++? Easy
Q11. What is a virtual function? Medium
struct Base { virtual void f() { cout << "B"; } };
struct Derived : Base { void f() override { cout << "D"; } };
Base* p = new Derived(); p->f(); // D
Q12. What is a vtable and vptr? Hard
Q13. What is a pure virtual function and an abstract class? Medium
Q14. Why should a base class destructor be virtual? Hard
Q15. What is the difference between overloading and overriding? Medium
Q16. What is the diamond problem and virtual inheritance? Hard
struct A {};
struct B : virtual A {};
struct C : virtual A {};
struct D : B, C {}; // one shared A
Q17. What does the override keyword do? Medium
Q18. Can constructors be virtual? Medium
Q19. What is object slicing? Hard
Resource Management
Q20. What is RAII? Medium
Q21. What is the rule of three? Medium
Q22. What is the rule of five? Hard
Q23. What are smart pointers? Medium
auto p = std::make_unique<int>(5); // auto-freed
Q24. What is the difference between unique_ptr and shared_ptr? Hard
Q25. What is a memory leak and how do smart pointers prevent it? Medium
Advanced
Q26. What are move semantics? Hard
Q27. What is the difference between static and dynamic binding? Medium
Q28. What is a friend function or class? Medium
Predict the Output
Snippet 1
struct Base { ~Base() { cout << "B "; } };
struct Derived : Base { ~Derived() { cout << "D "; } };
Base* p = new Derived();
delete p;
Output:
B
Why: The non-virtual base destructor means only ~Base runs, leaking the derived part (undefined behaviour). Make ~Base virtual to print "D B".
Snippet 2
struct A { virtual void f() { cout << "A"; } };
struct B : A { void f() override { cout << "B"; } };
A a = B();
a.f();
Output:
A
Why: Assigning a B to an A value slices off the derived part, so a is a pure A and calls A::f.
Snippet 3
struct A { A() { cout << "A"; } virtual void g() {} };
struct B : A { B() { cout << "B"; } };
B b;
Output:
AB
Why: Base constructor runs before the derived constructor, so "A" prints before "B".
Quick Revision Table
| Concept | Key takeaway |
|---|---|
| virtual function | runtime dispatch via vtable |
| pure virtual | abstract class, must override |
| virtual destructor | required for polymorphic base |
| rule of three / five | destructor implies copy and move |
| RAII | resource tied to object lifetime |
| smart pointers | unique exclusive, shared counted |
| object slicing | pass by value loses derived part |
Frequently Asked Questions
What C++ OOP topic is asked most in 2026?
Candidates report that virtual functions and the vtable, the difference between virtual and pure virtual, and why a base class destructor should be virtual are the three most repeated C++ OOP questions.
Is the rule of three or five asked in interviews?
Yes. Interviewers expect you to explain that if you define a destructor, copy constructor, or copy assignment you usually need all of them, and with move semantics the rule extends to five.
What is RAII and why does it matter?
RAII ties resource lifetime to object lifetime so destructors release resources automatically, even on exceptions. It is the foundation of safe C++ and a guaranteed interview topic for systems roles.
Why should a base destructor be virtual?
Deleting a derived object through a base pointer with a non-virtual destructor only runs the base destructor, leaking the derived part and causing undefined behaviour. A virtual destructor ensures the full destruction chain runs.
What is the difference between unique_ptr and shared_ptr?
unique_ptr is exclusive, non-copyable ownership with no overhead, while shared_ptr is reference-counted shared ownership that frees the object when the count reaches zero. Prefer unique_ptr unless sharing is genuinely required.
Related Articles
- C++ Programming Placement Questions, the master set
- C++ STL Interview Questions 2026, containers and algorithms
- C++ Pointers Interview Questions 2026, memory and pointers
- Java OOPs Interview Questions 2026, compare with Java's model
Confirm any object-model detail on the official cppreference documentation before your interview. This guide reflects candidate-reported patterns and public preparation resources as of June 2026.
Methodology applied to this articlelast verified 8 Jun 2026
- No fabricated salary numbers or success rates. If we quote a range, it's sourced.
- No noun-substituted templates. This article was not generated by swapping company names in a stock prompt.
- No paid placements, sponsored coaching links, or affiliate-shilled course pushes.
Explore this topic cluster
More resources in Interview Questions
Use the category hub to browse similar questions, exam patterns, salary guides, and preparation resources related to this topic.
Paid contributor programme
Sat this this year? Share your story, earn ₹500.
First-person experience reports help future candidates prep smarter. We pay verified contributors ₹500 via UPI per accepted story - with byline.
Submit your story →Ready to practice?
Take a free timed mock test
Put what you learned into practice. Our mock tests match the 2026 pattern with timer, navigator, reveal, and score breakdown. No signup.
Start Free Mock Test →Related Articles
Airbnb Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airbnb's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Airtel Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Airtel's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
AMD Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing AMD's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical, behavioural,...
Atlassian Interview Questions 2026: Top Tech, HR & Behavioural Q&As for Freshers
Clearing Atlassian's fresher loop in 2026 comes down to preparing for the exact mix of questions across technical,...
Barclays Interview Questions 2026
_Last verified by [Aditya Sharma](/author/aditya-sharma/) · cross-checked against PapersAdda Hiring Pulse and...
More from PapersAdda
Accenture Interview Process 2026: Rounds & Prep
Accenture Interview Questions 2026 (with Answers for Freshers)
Adobe Interview Process 2026: Rounds, OA & Aptitude
Amazon Interview Process 2026: Full Loop + Bar Raiser