D
DevPrepSystematic Prep
OOPS · MEDIUM CODEX

OOPs Interview Questions — Medium

Real-world mechanisms, state management, edge cases, performance trade-offs, and practical coding.

50 Theory Questions5 Free Model Answers
THEORY QUESTIONS & SOLUTIONSShowing 5 of 50 questions
Q1How do abstract classes and interfaces differ in terms of architectural design intent?
  • Abstract Class (Identity): Establishes an "Is-A" relationship. It represents a strict taxonomic lineage, sharing core structural state and common base implementations. Use it when subclasses are fundamentally related.
  • Interface (Capability): Establishes a "Can-Do" contract. It defines a protocol or behavioral capability that can be implemented by entirely unrelated classes. Use it to support horizontal decoupling.
Q2What is dynamic method dispatch, and how does the runtime resolve which method to call?
  • Definition: The mechanism where a call to an overridden method is resolved at runtime instead of compile-time.
  • Resolution Process: The runtime inspects the actual object instance in memory (not the reference pointer type). It uses the object's internal type metadata to lookup and execute the specific overriding method defined in that object's class.
Q3What is the Virtual Method Table (VTable) and how is dynamic dispatch implemented under the hood?
  • VTable: A lookup table of function pointers created by the compiler for any class containing virtual methods. Each class has exactly one static VTable.
  • VPTR: An implicit pointer added to the memory layout of each object instance pointing to its class's VTable.
  • Resolution: During a virtual call, the compiled code dereferences the object's VPTR, navigates to the class's VTable, and jumps to the function pointer at the designated offset. This adds a slight runtime overhead of double-indirection.
Q4What is object slicing in C++, and why does it not occur in languages like Java or C#?
  • Object Slicing: Occurs in C++ when a subclass object is assigned by-value to a parent class object. The subclass-specific member variables are "sliced away" because the parent object's memory footprint is too small.
  • Java/C# Exemption: These languages handle objects exclusively by-reference on the heap. Assigning a subclass reference to a parent reference only copies the reference pointer, not the underlying object data.
Q5Explain the difference between early (static) binding and late (dynamic) binding.
  • Early Binding: Occurs at compile-time. The compiler matches method calls directly to specific memory addresses. It is fast, highly optimizable, and applies to static, private, and final methods.
  • Late Binding: Occurs at runtime. The target method is resolved dynamically using virtual tables. It supports polymorphism but incurs slight indirection overhead.

Unlock the remaining 45 OOPs (Medium) questions

You've completed the 5 free sample questions. Get unrestricted lifetime access to every question, model answer, implementation challenge, and all 27+ technologies for a single payment.

₹399 India / $9 International · One-time settlement · Zero subscription

CROSS-DIFFICULTY NAVIGATION

Continue Preparing OOPs

OOPs Interview Questions (Medium) | DevPrep | DevPrep