DEV Community

Raja B
Raja B

Posted on

Java Basic Concepts

basic

Object-Oriented Programming (OOP) is a programming style that organizes code around objects—things that contain both data and actions. The four core OOP concepts are encapsulation, abstraction, inheritance, and polymorphism.

Basic building blocks

Before the four pillars, understand these two terms:

Term Meaning Real-life example
Class A blueprint/template for creating objects A Car design
Object A real item created from a class A specific red Tesla car
In Java:
class Car 
{
    String brand;
    int speed;

    void drive() 
    {
        System.out.println(brand + " is driving");
    }
}

Car car1 = new Car();
car1.brand = "Tesla";
car1.speed = 100;

car1.drive();
Enter fullscreen mode Exit fullscreen mode
Here:
  • Car is the class

  • car1 is an object

  • brand and speed are data/properties

  • drive() is an action/method

An object is a software bundle of related state (data) and behavior (methods)

The four OOP concepts

Concept Simple meaning Main purpose
Encapsulation Protect data inside an object Control and validate data changes
Abstraction Show only what is needed Hide unnecessary complexity
Inheritance Child class reuses parent class features Reduce repeated code
Polymorphism Same method call, different behavior Write flexible code
Reference:

Top comments (0)