OOPs Concepts in Java: Encapsulation, Abstraction, Inheritance, Polymorphism
Object-Oriented Programming (OOPs) in Java is built around four core concepts that work together to make code modular, reusable, and easier to maintain.
1. Encapsulation
Encapsulation bundles data and methods into a single class and restricts direct access to fields using private access modifiers and public getters/setters.
class Account {
private double balance;
public double getBalance() { return balance; }
}
2. Abstraction
Abstraction hides implementation details and exposes only the essential features, typically using abstract classes or interfaces.
abstract class Shape {
abstract double area();
}
3. Inheritance
Inheritance allows a class to acquire the fields and methods of another class using the extends keyword, promoting code reuse.
class Vehicle {
void start() { System.out.println("Vehicle starting"); }
}
class Car extends Vehicle { }
4. Polymorphism
Polymorphism allows one interface or method to take multiple forms — through method overloading (compile-time) and method overriding (runtime).
class Shape {
void draw() { System.out.println("Drawing a shape"); }
}
class Circle extends Shape {
@Override
void draw() { System.out.println("Drawing a circle"); }
}
Why These Concepts Matter
- They make large codebases easier to organize and reason about
- They promote code reuse and reduce duplication
- They make programs more flexible and easier to extend over time
Master Java with Uncodemy
Hands-on training, live projects, and placement support in our Java Programming Course.