OOPs Concepts in Java
OOPs Concepts in Java
SJEFF
What is OOPS?
An object can be defined as an instance of a class, and there can be multiple instances
of a class in a program. An Object is one of the Java OOPs concepts which contains both
the data and the function, which operates on the data. For example – chair, bike,
marker, pen, table, car, etc.
Inheritance
Inheritance is one of the Basic Concepts of OOPs in which one object acquires the
properties and behaviors of the parent object. It’s creating a parent-child relationship
between two classes. It offers robust and natural mechanism for organizing and
structure of any software.
Polymorphism
Abstraction is one of the OOP Concepts in Java which is an act of representing essential
features without including background details. It is a technique of creating a new data
type that is suited for a specific application. Lets understand this one of the OOPs
Concepts with example, while driving a car, you do not have to be concerned with its
internal working. Here you just need to concern about parts like steering wheel, Gears,
accelerator, etc.
Encapsulation
Encapsulation is one of the best Java OOPs concepts of wrapping the data and code. In
this OOPs concept, the variables of a class are always hidden from other classes. It can
only be accessed using the methods of their current class. For example – in school, a
student cannot exist without a class.
Association
Association is a relationship between two objects. It is one of the OOP Concepts in Java
which defines the diversity between objects. In this OOP concept, all objects have their
separate lifecycle, and there is no owner. For example, many students can associate
with one teacher while one student can also associate with multiple teachers.
Aggregation
In this technique, all objects have their separate lifecycle. However, there is ownership
such that child object can’t belong to another parent object. For example consider
class/objects department and teacher. Here, a single teacher can’t belong to multiple
departments, but even if we delete the department, the teacher object will never be
destroyed.
Composition
• OOPs Concepts in Java offer easy to understand and a clear modular structure for
programs.
• Objects created for Object-Oriented Programs can be reused in other programs. Thus it
saves significant development cost.
• Large programs are difficult to write, but if the development and designing team follow
OOPS concepts, then they can better design with minimum flaws.
• It enhances program modularity because every object exists independently.
Comparison of OOPS with other
programming styles with help of an
Example
Let’s understand with example how Java OOPs Concepts are different than other
programming approaches.
Programming languages can be classified into 3 primary types
1. Unstructured Programming Languages: The most primitive of all programming
languages having sequentially flow of control. Code is repeated through out the
program
2. Structured Programming Languages: Has non-sequentially flow of control. Use of
functions allows for re-use of code.
3. Object Oriented Programming Languages: Combines Data & Action Together.
et’s understand these 3 types with an example.
Suppose you want to create a Banking Software with functions like
1. Deposit
2. Withdraw
3. Show Balance
Unstructured Programming Languages