Java Tutorial - 4 OOPS Concepts in JAVA with Realtime Examples

In this post, We will explore 4 main OOPS concepts in JAVA with Realtime Examples.

4 OOPS Concepts in JAVA with Realtime Examples

In this section, our mainly focus 4 main concepts in Java and I think this 4 main concepts in Java are necessary.

  1. Inheritance
  2. Polymorphism
  3. Encapsulation
  4. Abstraction

Before we will go ahead in this post, Let's we discuss about the OOPS.

What is OOPS Concepts?

OOPS is stands for Object Oriented Programming Concepts. Many programming language follow OOPS concepts like JAVA, PL/SQL,C++.

OOPS concepts highlighted because of OOPS concepts give more maintainability and flexibility.

Given the above points is called as Four Pillars of OOPS Concepts. So today in this section, I will describe about the Four Pillars of OOPS Concepts.

Inheritance: Inheritance is an important pillar of OOP(Object Oriented Programming). It is the mechanism in java by which one class is allowed to inherit the features(fields and methods) of another class.

Super Class: The class whose features are inherited is known as superclass(or a base class or a parent class).

Sub Class: The class that inherits the other class is known as subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the Superclass fields and methods.

Example:-Some properties of the father are inherited by his son.

PolymorphismWe can define polymorphism as the ability of a message to be displayed in more than one form.

Example. A person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism.

Example:- Two or more functions have the same name but different parameters
void show(int a , int b)
void show(Double a, Double b)
void show(int a, int b , int c)

EncapsulationEncapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. Another way to think about encapsulation is, it is a protective shield that prevents the data from being accessed by the code outside this shield.

Example. A medicine capsule inner part can not be accessible by the patient it directly goes to the stomach and does its work.

AbstractionData Abstraction is the property by which only the essential details are displayed to the user. The non-essentials units are not displayed to the user.
Example: A car is viewed as a car rather than its individual components.

That's all for today.I think 4 OOPS concepts in Java with Realtime Examples blog post helps.If you like the post then share your valuable comment.

Post a Comment