Loading...
By KarnatakaPUCS Team on 7/10/2026
Object-Oriented Programming (OOP) is a fundamental paradigm in Java. This guide covers the four pillars of OOP and how to apply them effectively.
Encapsulation bundles data and methods together, hiding internal details:
javapublic class BankAccount { private double balance; public void deposit(double amount) { if (amount > 0) { balance += amount; } } public double getBalance() { return balance; } }
Inheritance allows classes to inherit properties from parent classes:
javapublic class Animal { public void eat() { System.out.println("Eating..."); } } public class Dog extends Animal { public void bark() { System.out.println("Woof!"); } }
Polymorphism allows objects to take many forms:
javapublic class Shape { public double area() { return 0; } } public class Circle extends Shape { private double radius; @Override public double area() { return Math.PI * radius * radius; } }
Abstraction hides complexity while showing only essential features:
javapublic abstract class Vehicle { abstract void start(); public void run() { start(); System.out.println("Vehicle is running"); } }