The 4 Types of OOPS Concepts, Explained With Examples

The four types of OOPS concepts are encapsulation, inheritance, polymorphism and abstraction. Object oriented programming means organising code around objects, and these four ideas are how it does that.

ConceptOne line definition
EncapsulationKeep data and its methods in one class, and hide the data
InheritanceA new class reuses the fields and methods of an existing class
PolymorphismThe same call runs different code depending on the real object
AbstractionExpose what an object does and hide how it does it

Some lists count classes and objects as a fifth item. The four above are the set interviewers expect.

Encapsulation

Encapsulation means the data of an object is private, and the only way in is through methods you control.

The benefit is that you can check every change. A balance that can only move through deposit and withdraw can never go negative by accident.

class BankAccount { private double balance; // hidden data public void deposit(double amount) { if (amount > 0) balance += amount; // the rule lives here } public double getBalance() { return balance; } }

Nothing outside the class can write balance. That is the whole point.

Inheritance

Inheritance lets a new class take the fields and methods of an existing one. The existing class is the parent or base class. The new one is the child or derived class.

It is often asked in a second form, the types of inheritance.

TypeShape
SingleOne child from one parent
MultilevelA child of a child, three or more levels deep
HierarchicalSeveral children from the same parent
MultipleOne child from two or more parents
HybridA mix of the types above

Java and C# do not allow multiple inheritance of classes. You get the same effect by implementing several interfaces. C++ does allow it, which is why it needs virtual inheritance to solve the diamond problem.

Prefer composition when the relationship is not a true "is a". A Car has an Engine, so it should hold one, not extend one.

Polymorphism

Polymorphism means one name and many behaviours. It comes in two kinds.

  • Compile time polymorphism. Method overloading. Two methods share a name and differ in their parameters, and the compiler picks one.
  • Run time polymorphism. Method overriding. A child class replaces a parent method, and the real object type decides which runs.

Abstraction

Abstraction means you publish the operations and hide the work behind them. Abstract classes and interfaces are the usual tools.

This example shows abstraction, inheritance and run time polymorphism together.

abstract class Animal { // abstraction abstract String speak(); } class Dog extends Animal { // inheritance String speak() { return "Woof"; } } class Cat extends Animal { String speak() { return "Meow"; } } public class Demo { public static void main(String[] args) { Animal a = new Dog(); System.out.println(a.speak()); // prints Woof } }

The variable is declared as Animal, so the caller does not know or care which animal it holds.

Classes you will be asked about

A follow up question often asks about kinds of classes, which is a different list.

  • Concrete class. A normal class you can create objects from.
  • Abstract class. Cannot be created directly, and may leave methods unimplemented.
  • Interface. Only a set of method signatures, with no state.
  • Final or sealed class. Cannot be extended.
  • Nested and inner class. A class declared inside another class.

How to Prepare

TAGS
Coding Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What is CICd in DevOps?
What is the data type in C++?
What company has the hardest coding interview?
What is the hardest part of a virtual interview?
Which industry has the most remote workers?
What does Microsoft hire for?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$98

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
About Us
Our Team
Careers
Partners
Contact Us
Become Affiliate
Copyright © 2026 Design Gurus, LLC. All rights reserved.