52 OOP Interview Questions & Answers
OOP interviews test whether you understand the reasoning behind the four pillars, not just their definitions — why encapsulation matters, what actually breaks the Liskov Substitution Principle, why multiple inheritance causes the diamond problem. This covers all 52 questions, with code (mostly C#, since that's this site's home turf, with cross-language notes where it matters), a diagram, and a mock test at the end.
OOP Fundamentals
Q1. What is Object-Oriented Programming (OOP)?
OOP is a programming paradigm that models software around objects — bundles of state (data) and behavior (methods) — rather than a sequence of procedures operating on separate data. It's built on four pillars: encapsulation, inheritance, polymorphism, and abstraction, each addressing a different way of managing complexity as a codebase grows.
Q2. What is the difference between procedural and Object-Oriented programming?
| Procedural | Object-Oriented | |
|---|---|---|
| Organization | Functions operating on separate data structures | Objects bundling data and the behavior that operates on it |
| State | Often global or passed explicitly between functions | Encapsulated within objects, accessed through methods |
| Reuse | Function libraries | Inheritance, composition, polymorphism |
| Example languages | C, Pascal | Java, C#, Python, C++ |
Q3. What is encapsulation?
public class BankAccount
{
private decimal _balance; // hidden — no direct outside access
public decimal Balance => _balance;
public void Deposit(decimal amount)
{
if (amount <= 0) throw new ArgumentException("Must be positive");
_balance += amount;
}
}Encapsulation bundles an object's data with the methods that operate on it, and hides that data behind a controlled interface — _balance can't be set to a negative number from outside because there's no way to touch it except through Deposit(), which enforces the invariant. This is what keeps an object's internal state always valid, instead of trusting every caller everywhere to maintain it correctly themselves.
Q4. What is polymorphism? Explain overriding and overloading.
| Overriding | Overloading | |
|---|---|---|
| What varies | The implementation of the same method signature, in a subclass | Multiple methods with the same name, different parameters |
| Resolved at | Runtime (based on the actual object's type) | Compile time (based on the arguments' types) |
| Requires | virtual/override keywords (or an interface implementation) | Just different parameter lists on the same class |
public class Shape { public virtual double Area() => 0; }
public class Circle : Shape
{
public double Radius;
public override double Area() => Math.PI * Radius * Radius; // overriding
}
public class Calculator
{
public int Add(int a, int b) => a + b;
public double Add(double a, double b) => a + b; // overloading
}Polymorphism means the same method call behaves differently depending on the actual object it's invoked on ("many forms") — calling shape.Area() through a Shape reference runs Circle's implementation if that's the real underlying object, resolved at runtime. Overloading is a different, compile-time mechanism entirely — picking which of several same-named methods to call based on argument types.
Q5. What is inheritance? Name some types of inheritance.
| Inheritance type | Shape |
|---|---|
| Single | One class inherits from one base class |
| Multiple | One class inherits from more than one base class (not supported by C#/Java for classes) |
| Multilevel | A chain — C inherits from B, B inherits from A |
| Hierarchical | Multiple classes inherit from the same base class |
Inheritance lets a class (the subclass) acquire the members of another class (the base class), modeling an "is-a" relationship — a Dog is an Animal. C# and Java deliberately don't allow multiple inheritance of classes (only of interfaces) specifically to avoid the diamond problem covered later.
Q6. What is an abstraction? Name some abstraction techniques.
Abstraction hides implementation complexity behind a simpler interface, exposing only what a consumer actually needs to know. Techniques: abstract classes (partial implementation plus abstract members to be filled in), interfaces (a pure contract with no implementation), and encapsulation itself (hiding internal state behind methods) all serve abstraction in different ways.
Q7. What is a class in OOP?
A class is a blueprint — it defines the fields (state) and methods (behavior) that every object created from it will have, but a class itself holds no actual data until it's instantiated.
Q8. What is an object in OOP?
var fido = new Dog { Name = "Fido" }; // fido is an object — a concrete instance of the Dog classAn object is a concrete instance of a class — it has its own actual state (its own values for the class's fields) in memory, distinct from every other instance of the same class.
Q9. How do access specifiers work and what are they typically?
| Access modifier (C#) | Visible to |
|---|---|
| public | Anywhere |
| private | Only within the same class |
| protected | The class and its subclasses |
| internal | Anywhere within the same assembly |
| protected internal | Subclasses, OR anywhere in the same assembly |
Access specifiers control which other code can see/use a given member — the enforcement mechanism that actually makes encapsulation possible, rather than encapsulation being just a naming convention developers have to remember to respect.
Q10. Name some ways to overload a method.
public void Print(int value) { ... }
public void Print(string value) { ... } // different parameter type
public void Print(int value, bool bold) { ... } // different parameter count
public void Print(double value) { ... } // different parameter type againOverloads must differ by parameter count and/or parameter types (or order) — return type alone isn't enough to distinguish two overloads, since the compiler resolves which overload to call based on the arguments at the call site, not the expected return value.
Enjoyed this?
Let's talk about building something together.