LearnThatStack Ace your next interview
C# · question
Question 5 of 112

Explain the four pillars of Object-Oriented Programming.

beginner
← All C# questions
Re-explain

Encapsulation bundles data with its methods and hides the internals, and inheritance builds a new class from an existing one to reuse its code. Polymorphism lets code use different types through one common type, and abstraction shows only the essential features.

C# has a language feature for each pillar:

  1. For encapsulation, access modifiers like private, plus properties.
  2. For inheritance, a single base class, as in class Car : Vehicle.
  3. For polymorphism, virtual and override methods and interfaces.
  4. For abstraction, abstract classes and interfaces.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • How is encapsulation different from abstraction? They both sound like hiding details. Encapsulation guards a class's state behind its members. Abstraction picks which operations callers see. Use one class to show both.
  • When would you use an abstract class instead of an interface? Cover shared state and constructors, one base class versus many interfaces, and a concrete case where you would pick each.
  • Is method overloading a form of polymorphism? How does it differ from overriding? The compiler resolves overloads from argument types. Overriding picks the method at runtime from the object's actual type, through virtual and override.
  • When would you choose composition over inheritance? Inheritance is an is-a link that ties you to the base class. Composition is has-a and lets you swap parts. Name a case for each.
  • Why does C# allow only one base class but let a class implement many interfaces? Mention the diamond problem, then explain that interfaces let a class take on several types without inheriting state from several bases.

What you can say

  1. The four pillars are encapsulation, inheritance, polymorphism and abstraction, and C# has a language feature for each one.
  2. Encapsulation bundles data with the methods that use it and hides the internals, so in C# I keep fields private and expose properties.
  3. Inheritance builds a new class from an existing one to reuse its code, like class Car : Vehicle, and a C# class gets a single base class.
  4. Polymorphism lets code work with different types through one common type, using virtual and override methods or interfaces.
  5. Abstraction shows only the essential features, through abstract classes and interfaces, so callers depend on what a type does rather than how.
  6. The pillar I'm most careful with is inheritance, because deep hierarchies couple classes tightly, so I often use interfaces and composition instead.

Weak answers to avoid

  • Recites four definitions with no code Interviewers want to see you apply the ideas. Tie each pillar to a C# feature, like private fields with properties or virtual and override, and give one short example.
  • Treats encapsulation and abstraction as the same Both hide something, but encapsulation guards a class's state and abstraction picks which operations callers see. Blurring them sounds like memorized terms.
  • Says C# supports multiple inheritance A C# class has exactly one base class. It can implement many interfaces, and that is how it takes on several types.
  • Presents inheritance as the default way to reuse code Deep hierarchies tie subclasses to base class details. Say you use inheritance for real is-a links and interfaces or composition otherwise.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the C# cheatsheet.

← Back to all C# questions
Pro · $10/mo

98 of 112 C# answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime