Java OOP(Object Oriented Programming) Concepts

Last Updated : 23 Jan, 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:

  • Improves code reusability
  • Enhances maintainability and scalability
  • Makes programs easier to understand and manage
  • Closely models real-world entities

Characteristics of an OOP(Object Oriented Programming)

The diagram below demonstrates the Java OOPs Concepts

Types-of-OOPS-2
OOP's concept

1. Class

A Class is a user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type. Using classes, you can create multiple objects with the same behavior instead of writing their code multiple times. In general, class declarations can include these components in order: 

  • Modifiers: A class can be public or have default access (Refer to this for details).
  • Class name: The class name should begin with the initial letter capitalized by convention.
  • Body: The class body is surrounded by braces, { }.

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

Class
class-object

2. Object

An Object is a basic unit of Object-Oriented Programming that represents real-life entities. A typical Java program creates many objects, which as you know, interact by invoking methods. The objects are what perform your code, they are the part of your code visible to the viewer/user. An object mainly consists of: 

  • State: It is represented by the attributes of an object. It also reflects the properties of an object.
  • Behavior: It is represented by the methods of an object. It also reflects the response of an object to other objects.
  • Identity: It is a unique name given to an object that enables it to interact with other objects.
  • Method: A method is a collection of statements that perform some specific task and return the result to the caller.

3. 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.

  • Hides complexity: Internal implementation details are hidden from the user.
  • Improves maintainability: Changes in implementation do not affect the user code.
  • Enhances flexibility: Supports loose coupling through abstract classes and interfaces.

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.

hides_certain_details_and_show_only_essential_information
Abstraction

How to Achieve Abstraction

abstraction

4. 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.

  • Data members are hidden using the private access modifier.
  • Access to data is provided through public getter and setter methods.
  • It improves data security, maintainability, and controlled access.
Encapsulation
Encapsulation

5. 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.

  • The class being inherited is called the superclass, and the inheriting class is the subclass.
  • A subclass can use existing features of the superclass and also add its own.
  • Inheritance promotes code reusability and reduces redundancy.

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

inheritance-660x454
Inheritance

Types of Inheritance in Java

inheritance_in_java

Java supports the following types of inheritance:

  • Single Inheritance: One subclass inherits from one superclass.
  • Multilevel Inheritance: A class is derived from another derived class, forming a chain.
  • Hierarchical Inheritance: Multiple subclasses inherit from a single superclass.
  • Multiple Inheritance (through Interface): A class inherits from multiple interfaces since Java does not support multiple inheritance using classes.
  • Hybrid Inheritance (through Interface): A combination of two or more types of inheritance, achievable using interfaces.

6. Polymorphism

The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity can take many forms. In Java, polymorphism allows the same method or object to behave differently based on the context, specially on the project's actual runtime class.

polymorphism_in_java
Polymorphism in Java

Types of Polymorphism

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

1. Compile-time Polymorphism(Method Overloading) :Achieved when multiple methods have the same name but different parameters. The method call is resolved at compile time.

2. Runtime Polymorphism (Method Overriding ): Achieved when a subclass provides a specific implementation of a method already defined in its superclass. The method call is resolved at runtime based on the object 

Advantage of OOP over Procedure-Oriented Programming Language

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

  • Code reusability: Classes and objects allow reuse of existing code, reducing duplication and improving efficiency.
  • Better structure and maintainability: Programs are organized into logical units, making code easier to understand, debug, and maintain.
  • Supports DRY principle: Common functionality is written once and reused, leading to cleaner and more maintainable code.
  • Faster development: Modular and reusable components help in quicker and scalable application development.

Disadvantages of OOP

  • Steep learning curve: Concepts like classes, objects, inheritance, and polymorphism can be difficult for beginners.
  • Overhead for small programs: OOP may require more code and structure than necessary for simple applications.
  • Debugging complexity: Code spread across multiple classes and layers can make debugging more time-consuming.
  • Higher memory usage: Creating many objects can consume more memory compared to procedural programs.
Comment