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:
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.
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
In Java, this refers to the current instance of the class.
It is used to:
-
Pass the current object as a parameter.
-
Refer to current class variables.
📌 Constructor
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:
-
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.
-
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.
-
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:
Method Overriding Example:
📌 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:
-
Single Inheritance – One class extends another. When one class inherits another class, it is known as single level inheritance.
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.
Multilevel Inheritance – A class derived from another derived class. Multilevel inheritance is a process of deriving a class from another derived class.
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
📌 Access Modifiers
-
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.
-
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.
-
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.
-
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 = 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).
📧 Contact: ishikhanirankari@gmail.com | info@realtechnologiesindia.com
🌐 Website: IT Trainings | Digital metal podium
Comments
Post a Comment