Java OOP(Object Oriented Programming) Concepts (original) (raw)

Last Updated : 6 Jun, 2026

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of objects that contain data (fields) and behavior (methods). It focuses on designing software that closely represents real-world entities. It is used to:

**Characteristics of OOP

The diagram below demonstrates the Java OOPs Concepts

object_oriented_programming

Object Oriented Programming

Class

A Class in Java is a blueprint or template used to create objects. It defines the properties (data) and behaviors (methods) that objects of that class will have.

**Example: A Car represents a class (blueprint), while BMW, Mercedes, and Audi represent objects (instances) created from that class.

Class

class-object

Object

An Object in Java is an instance of a class that represents a real-world entity. It is used to access the variables and methods defined inside a class.

**Example: Dog is a class, Tommy is an object of that class.

Object

Object

Constructor

A Constructor is a special member of a class that is automatically invoked when an object is created. It is primarily used to initialize the object's data members and set up the initial state of an object.

**Example: When creating a Car object, a constructor can automatically assign values such as brand, model, and color.

Types of Constructor

constructors_in_java

Abstraction

Abstraction in Java is the process of hiding implementation details and showing only the essential features of an object. It helps users focus on what an object does rather than how it does it.

**Example: An ATM or a coffee machine represents abstraction, where the user interacts with simple operations while the internal working and implementation details remain hidden.

Abstraction

Abstraction

How to Achieve Abstraction

abstraction

Achieve Abstraction

**Example: Abstract class defines a common base (Shape) using inheritance, while an interface (Drawable) defines behavior implemented by multiple classes.

abstract_class

abstract-class-interface

Encapsulation

Encapsulation is the process of wrapping data and methods into a single unit, usually a class, and restricting direct access to the data. It acts as a protective shield that prevents data from being accessed directly from outside the class.

Encapsulation

Encapsulation

Association

Association is an OOP concept that defines a relationship between two or more classes that are connected to each other. It represents how objects interact with each other and communicate. In association, objects of one class are related to objects of another class, but they can exist independently.

Types of Association

Association in Java can be further classified into the following types:

1. Aggregation (Weak Association)

Aggregation represents a “has-a” relationship where one class contains a reference to another class, but both can exist independently.

**Example: A Company has Employees, but employees can exist independently even if the company no longer exists.

aggregation_relationship

Aggregation

2. Composition (Strong Association)

Composition is a strong form of association where one class owns another class. If the parent object is destroyed, the child object also gets destroyed.

**Example: A House is composed of Rooms, and if the house is destroyed, the rooms cannot exist independently.

composition_relationship

Inheritance

Inheritance is a core OOP concept in Java that allows one class to acquire the fields and methods of another class using the extends keyword. It represents an “is-a” relationship between classes.

**Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.

inheritance-660x454

Inheritance

Types of Inheritance

inheritance_in_java

Java supports the following types of inheritance:

**Polymorphism

Polymorphism means “many forms”, where a single entity can behave differently in different situations. In Java, it allows the same method or object to show different behavior based on context.

**Example: Different animals represent polymorphism, where the same method speak() produces different outputs like Bark, Meow, and Moo depending on the object.

Polymorphysm

Polymorphism

Types of Polymorphism

Polymorphism in Java is mainly of 2 types as mentioned below:

polymorphism_in_java

Polymorphism in Java

Advantage of OOP over Procedure-Oriented Programming Language

Object-oriented programming (OOP) offers several key advantages over procedural programming:

Limitations of OOP

While OOP provides many benefits, it also has some limitations: