December Code

OOP · 14 topic pages · 90 questions in the bank

OOP for placements: interview questions by topic

Interviewers use object-oriented questions to find out whether you can explain a concept with a concrete example, not recite its definition. 'What is polymorphism?' is followed by 'show me one', then 'is that compile-time or runtime, and how do you know?'. The pairs are where the marks are: inheritance versus composition, overloading versus overriding, interface versus abstract class, encapsulation versus the access modifiers that implement it, static versus instance members, this versus super.

The questions are language-neutral in intent and language-specific in detail, so the answers below say which behaviour is Java's and which is C++'s wherever they differ — constructors and destructors especially. SOLID principles appear in product-company rounds as 'what is wrong with this class', and the honest answer usually names one principle and one fix.

Two habits carry most of the round. Answer with a two-class example you can write on paper in a minute — a base class, a subclass, one overridden method — and then say what changes at compile time versus runtime. And when asked for a definition, give the definition, the example, and the one mistake people make with it, in that order; interviewers stop asking once they hear the third part.

Each page below covers one concept: the questions interviewers actually ask, answers with short code, the follow-ups, and one question exactly as the diagnostic asks it. The diagnostic draws from every OOP topic in the bank and tells you which concepts you can define but not apply.

New to this? How to prepare for placements — the method — and what the readiness test measures.

OOP topics, one page each

oop/14 of 15 topics have a page · the diagnostic draws from all 15
  1. Inheritance interview questionsTypes of inheritance, constructor order, overriding rules, the diamond problem, composition vs inheritance, upcasting and slicing — in Java and C++.
  2. Polymorphism interview questionsCompile-time vs runtime polymorphism, overloading vs overriding, virtual dispatch, why C++ needs virtual, static methods, virtual destructors — answered.
  3. Interface vs abstract class interview questionsInterface vs abstract class, when to choose which, default methods, constructors, the two-defaults conflict, marker and functional interfaces.
  4. Method overloading vs overriding interview questionsOverloading vs overriding, return-type overloads, override rules, which overload the compiler picks, static methods, covariant returns — answered.
  5. Encapsulation interview questionsEncapsulation vs abstraction, data hiding, getters and setters vs public fields, leaking mutable state, immutable classes, tell-don't-ask.
  6. SOLID principles interview questionsAll five SOLID principles with the violation each prevents — SRP, Open/Closed, Liskov and the square-rectangle trap, ISP, dependency inversion.
  7. Constructor and destructor interview questionsDefault and parameterised constructors, no return type, this() chaining, super() and the missing no-arg constructor, copy constructors, destructors.
  8. Static vs instance member interview questionsWhat static means, why static methods can't touch instance fields, static block order, why main is static, static nested classes, hiding.
  9. Access modifier interview questionspublic, private, protected and package-private in one table, protected across packages, top-level class rules, override access, C++ private inheritance.
  10. this and super keyword interview questionsWhat this refers to, shadowed fields, this() and super() in constructors, super.method() from an override, passing and returning this, static context.
  11. Classes and objects interview questionsClass vs object, what a declaration without new does, copying references, pass-by-value, object lifecycle and garbage collection, equals vs ==, records.
  12. Abstraction vs encapsulation interview questionsAbstraction vs encapsulation past the one-liners: what each solves, one without the other, the Java features for each, and leaky abstractions.
  13. Diamond problem interview questionsThe diamond problem in multiple inheritance: duplicated state and ambiguous calls, C++ virtual inheritance, Python's MRO and Java's default rules.
  14. Virtual functions interview questionsVirtual functions past 'use the virtual keyword': when a call binds, vtables, calls from constructors, default arguments, override, final and Java.

One question, exactly as the diagnostic asks it

From the OOP bank — 90 questions across 15 topics. The answer is marked because this one is public; in a sitting you choose first, then see why each option is right or wrong.

Inheritance · easyOOP-004

What is 'inheritance' in object-oriented programming?

  1. 1A mechanism where multiple methods share the same name but different parameter lists.
  2. 2A mechanism where a new class acquires the properties and behavior of an existing class.correct
  3. 3A mechanism where a class is prevented from being instantiated directly.
  4. 4A mechanism where an object's internal data is hidden from other classes.

Inheritance lets a derived (child) class reuse and extend fields/methods of a base (parent) class, promoting code reuse and establishing an 'is-a' relationship. Several methods sharing a name with different parameter lists is overloading; hiding an object's internal data from other classes is encapsulation; and preventing a class from being instantiated directly describes an abstract class.

More on this topic: Inheritance interview questions

Measure it

Reading the answers tells you what’s true. A diagnostic tells you what you get wrong.

10 OOP questions across its topics, easy to hard, about fifteen minutes. You get a readiness figure with the arithmetic shown, the topics you missed named, and a practice set sized for today. Free: a diagnostic in every subject, a retake a month and 15 problems a day. No card.

By Harshit · updated