πŸ”·OOP Concepts in Java

Object-Oriented Programming (OOP) is the foundation of Java. It helps build structured and reusable code.

1. Four Pillars of OOP

  1. Encapsulation – Protecting data using classes + getters/setters
  2. Inheritance – Reusing features from parent to child
  3. Polymorphism – Same method behaving differently
  4. Abstraction – Showing only important details

2. Simple Example

class Car {
void start() {
System.out.println(“Car starts”);
}
}

class Tesla extends Car {
void start() {
System.out.println(“Tesla starts silently”);
}
}

This is polymorphism through method overriding.

Leave a Comment

Your email address will not be published. Required fields are marked *