OOPs Concepts in Java | English | Object Oriented Programming Explained

🔹OOPS (Object Oriented Programming System) in Java

Object-Oriented Programming (OOPS) is a programming paradigm that uses classes and objects to design software. It simplifies development and maintenance by applying key concepts:


📌 Class: Class is a user-defined data type which defines its properties and its functions. Class is the only logical representation of the data. For example, Human beings in an organisation is a class like Employee. The age, name, department, salary etc. of a human being/employee are its properties, and the jobs performed by the employees in an organisation are known as functions. The class does not occupy any memory space till the time an object is instantiated.

A class is a user-defined data type that defines properties and functions.
For example:

  • Class: Employee

  • Properties: name, age, salary

  • Functions: work(), attendMeeting()

A class does not occupy memory until an object is created.


📌 Object: Object is a run-time entity. It is an instance of the class. An object can represent a person, place or any other item. For example, a person named John in an organisation is an object of class Employee. An object can operate on both data members and member functions.

An object is an instance of a class and represents a real-world entity.
Example:

  • John (Employee object of class Employee)

Objects can access both data members and member functions.





  • Note: When an object is created using a new keyword, then space is allocated for the variable in a heap, and the starting address is stored in the stack memory.


📌 this Keyword

‘this’ keyword in Java that refers to the current instance of the class. In OOPS it is used to:1. pass the current object as a parameter to another method.2. refer to the current class instance variable. Constructor: Constructor is a special method which is invoked automatically at the time of object creation. It is used to initialise the data members of new objects generally.

In Java, this refers to the current instance of the class.
It is used to:

  1. Pass the current object as a parameter.

  2. Refer to current class variables.


📌 Constructor

Constructors have the same name as class or structure. Constructors don’t have a return type (Not even void). Constructors are only called once, at object creation.

A constructor is a special method automatically invoked during object creation.

  • Has the same name as the class

  • No return type (not even void)

  • Used to initialize objects

There are 3 types of Constructors:

  1. Non-Parameterized: No arguments, sets default values. A constructor which has no argument is known as non-parameterised constructor (or no-argument constructor). It is invoked at the time of creating an object. If we don’t create one, then it is created by default by Java.

  2. Parameterized: Accepts arguments to set values. Constructor which has parameters is called a parameterised constructor. It is used to provide different values to distinct objects.

  3. Copy Constructor: Initializes an object using another object (user-defined in Java). A Copy constructor is an overloaded constructor used to declare and initialise an object from another object. There is only a user defined copy constructor in Java (C++ has a default one too).

👉 Note: Java has no destructor — it uses a garbage collector. Instead, Java has an efficient garbage collector that deallocates memory automatically.


📌 Polymorphism

Polymorphism is the ability to present the same interface for differing underlying forms (data types). With polymorphism, each of these classes will have different underlying data. Precisely, Poly means ‘many’ and morphism means ‘forms’, so polymorphism means 1 with many forms.

Polymorphism = “one interface, many forms.”

Types:

  • Compile-Time (Static) → Method Overloading. The polymorphism which is implemented at the compile time is known as compile-time polymorphism. Example - Method Overloading. Method Overloading: Method overloading is a technique which allows you to have more than one function with the same function name but with different functionality. Method overloading can be possible on the following basis: 

    1. The type of the parameters passed to the function.

    2. The number of parameters passed to the function.

  • Runtime (Dynamic) → Method Overriding. Runtime polymorphism is also known as dynamic polymorphism. Function overriding is an example of runtime polymorphism. Function overriding means when the child class contains the method which is already present in the parent class. Hence, the child

    class overrides the method of the parent class. In case of function overriding, parent and child classes both contain the same function with a different definition. The call to the function is determined at runtime is known as runtime polymorphism.

Method Overloading Example:

class MathOps { int add(int a, int b) { return a+b; } double add(double a, double b) { return a+b; } }

Method Overriding Example:

class Animal { void sound() { System.out.println("Animal makes sound"); } } class Dog extends Animal { void sound() { System.out.println("Dog barks"); } }

📌 Inheritance

Inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such a way, you can reuse, extend or modify the attributes and behaviors which are defined in other classes. In Java, the class which inherits the members of another class is called derived class and the class whose members are inherited is called base class. The derived class is the specialised class for the base class.

Inheritance allows one class (child) to acquire properties and methods of another (parent).

Types of Inheritance:

  1. Single Inheritance – One class extends another. When one class inherits another class, it is known as single level inheritance.


  2. Hierarchical Inheritance – Multiple classes extend one base class. Hierarchical inheritance is defined as the process of deriving more than one class from a base class. 


  3. Multilevel Inheritance – A class derived from another derived class. Multilevel inheritance is a process of deriving a class from another derived class. 


  4. Hybrid Inheritance – Combination of multiple types. Hybrid inheritance is a combination of simple, multiple inheritance and hierarchical inheritance. 





📌 Package in Java

Package is a group of similar types of classes, interfaces and sub-packages. Packages can be built-in, or user defined. Built-in packages - java, util, io etc.

A package is a group of related classes and interfaces.

  • Built-in Packages: java, util, io

  • User-defined Packages: Created by developers

import java.util.Scanner;




📌 Access Modifiers

  1. Private → Accessible only within the class. The access level of a private modifier is only within the class. It cannot be accessed from outside the class.

  2. Default → Accessible within the package. The access level of a default modifier is only within the package. It cannot be accessed from outside the package. If you do not specify any access level, it will be the default.

  3. Protected → Accessible within package + child classes. The access level of a protected modifier is within the package and outside the package through child class. If you do not make the child class, it cannot be accessed from outside the package.

  4. Public → Accessible everywhere. The access level of a public modifier is everywhere. It can be accessed from within the class, outside the class, within the package and outside the package.


📌 Encapsulation

Encapsulation is the process of combining data and functions into a single unit called class. In Encapsulation, the data is not accessed directly; it is accessed through the functions present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes. Thus, encapsulation makes the concept of data hiding possible. (Data hiding: a language feature to restrict access to members of an object, reducing the negative effect due to dependencies. e.g. "protected", "private" feature in Java).

Encapsulation = Binding data + methods in one unit (class).

  • Attributes are private

  • Accessed via public getters and setters

👉 Ensures data hiding.


📌 Abstraction

We try to obtain an abstract view, model or structure of a real-life problem, and

reduce its unnecessary details. With definition of properties of problems, including the data which are affected and the operations which are identified, the model abstracted from problems can be a standard solution to this type of problems. It is an efficient way since there are nebulous real-life problems that have similar properties. In simple terms, it is hiding the unnecessary details & showing only the essential parts/functionalities to the user.

Abstraction = Hiding unnecessary details, showing only essential features.

Example: A Car class may hide the complexity of engine operations but expose methods like drive() or brake().


📌 Data Binding

Data binding is a process of binding the application UI and business logic. Any change made in the business logic will reflect directly to the application UI. 

Data binding links UI and business logic so that changes in one reflect in the other.

👉Watch OOPs Concepts in Java in Action better:

Here's a quick video to help you understand OOPs Concepts in Java in Action better: 



✅ Conclusion

OOPs in Java introduces powerful concepts like Encapsulation, Inheritance, Polymorphism, and Abstraction, which make software more modular, reusable, and maintainable.

💼 Professional Support Available

If you are facing issues in real projects related to enterprise backend development or workflow automation, I provide paid consulting, production debugging, project support, and focused trainings.

Technologies covered include Java, Spring Boot, PL/SQL, Azure, and workflow automation (jBPM, Camunda BPM, RHPAM).




Comments

Popular posts from this blog

jBPM Installation Guide: Step by Step Setup

Scopes of Signal in jBPM