Home
All articles
OOPDesign PatternsInterview PrepC#

52 OOP Interview Questions & Answers

August 19, 202635 min read

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.

0 / 52 blocks read

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?

ProceduralObject-Oriented
OrganizationFunctions operating on separate data structuresObjects bundling data and the behavior that operates on it
StateOften global or passed explicitly between functionsEncapsulated within objects, accessed through methods
ReuseFunction librariesInheritance, composition, polymorphism
Example languagesC, PascalJava, C#, Python, C++

Q3. What is encapsulation?

csharp
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.

OverridingOverloading
What variesThe implementation of the same method signature, in a subclassMultiple methods with the same name, different parameters
Resolved atRuntime (based on the actual object's type)Compile time (based on the arguments' types)
Requiresvirtual/override keywords (or an interface implementation)Just different parameter lists on the same class
csharp
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 typeShape
SingleOne class inherits from one base class
MultipleOne class inherits from more than one base class (not supported by C#/Java for classes)
MultilevelA chain — C inherits from B, B inherits from A
HierarchicalMultiple 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?

csharp
var fido = new Dog { Name = "Fido" };   // fido is an object — a concrete instance of the Dog class

An 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
publicAnywhere
privateOnly within the same class
protectedThe class and its subclasses
internalAnywhere within the same assembly
protected internalSubclasses, 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.

csharp
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 again

Overloads 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.

Page16