Edumat LogoEduMat.in

Java Oops Concept Notes

mukesh juadi
mukesh juadi

Developer passionate about merging technology and creativity in software, games, websites, and more to create engaging experiences.

Comprehensive notes on OOP fundamentals. Master Objects, Classes, and the 4 pillars: Inheritance, Encapsulation, Polymorphism, and Abstraction.

ComputerDOCS4 pages
Thumbnail 11
Thumbnail 22
Thumbnail 33
Thumbnail 44
Java OOPs Concepts

In this page, we will learn about the basics of OOPs. Object-Oriented Programming is a paradigm that provides many concepts such as inheritance, data binding, polymorphism, etc.

OOPs (Object-Oriented Programming System)

An Object means a real-world entity such as a pen, chair, table, computer, watch, etc.

Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies software development and maintenance by providing the following concepts:

Object

Class

Inheritance

Polymorphism

Abstraction

Encapsulation

Apart from these concepts, there are some other terms used in Object-Oriented design:

Coupling

Cohesion

Association

Aggregation

Composition
Object

Any entity that has state and behavior is known as an object.
For example: a chair, pen, table, keyboard, bike, etc. It can be physical or logical.

An object can be defined as an instance of a class. An object contains an address and takes up some space in memory.

Objects can communicate without knowing the details of each other's data or code. The only necessary thing is the type of message accepted and the type of response returned by the objects.

Example:
A dog is an object because it has states like color, name, breed, etc., and behaviors like wagging the tail, barking, eating, etc.

Class

A collection of objects is called a class. It is a logical entity.

A class can also be defined as a blueprint from which you can create individual objects. A class does not consume memory space.

Inheritance

When one object acquires all the properties and behaviors of a parent object, it is known as inheritance.

It provides code reusability and is used to achieve runtime polymorphism.

Polymorphism

If one task is performed in different ways, it is known as polymorphism.

For example:

To convince the customer differently

To draw different shapes such as triangle, rectangle, etc.

In Java, we use method overloading and method overriding to achieve polymorphism.

Another example:
A cat speaks “meow,” a dog barks “woof,” etc.
Abstraction

Hiding internal details and showing only functionality is known as abstraction.

For example, when making a phone call, we do not know the internal processing.

In Java, we use abstract classes and interfaces to achieve abstraction.

Encapsulation

Binding or wrapping code and data together into a single unit is known as encapsulation.

For example, a capsule contains different medicines wrapped together.

A Java class is an example of encapsulation.
A Java Bean is a fully encapsulated class because all the data members are private.

Coupling

Coupling refers to the knowledge, dependency, or information of one class about another class.

If a class has detailed information about another class, it is called strong coupling.

In Java, we use private, protected, and public access modifiers to define visibility levels.

Interfaces help achieve weaker coupling because they do not provide concrete implementation.

Cohesion

Cohesion refers to the level at which a component performs a single well-defined task.

A highly cohesive method performs a single task efficiently.
A weakly cohesive method splits tasks into separate parts.

Example:

java.io package is highly cohesive because it contains I/O-related classes.

java.util package is weakly cohesive because it contains unrelated classes.

Association

Association represents the relationship between objects.

One object can be associated with one or many objects.

Types of association:

One to One

One to Many

Many to One

Many to Many

Example:

One country has one Prime Minister (One to One).

A Prime Minister has many ministers (One to Many).

Many MPs have one Prime Minister (Many to One).

Many ministers manage many departments (Many to Many).

Association can be unidirectional or bidirectional.
AI-Saathi AI-Saathi