oops concepts in java logo

OOPS Concepts in Java

Sushma Baliza Java 0 Comments

In software development, we provide solutions to real life problems of people. Whereas, object oriented programming(OOP) is a programming technique which is inspired by real life objects, their properties and behaviors. Hence, arised this object oriented approach. Java is one of the programming languages, which uses this object oriented paradigm. This article gives a brief overview of OOPS concepts in Java.

Object oriented programming or OOPS Concepts in java are basic and very important concept to understand how the java works.

List of OOPS Concepts in Java

  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance

Related Links:

Java Interview Questions

Let’s have a look over these concepts one-by-one.oops concepts in java logo

1. Abstraction

Abstraction is a process of hiding the implementation details and displaying only functionality to the user. In other words, it only displays essential things to the user and inner details are hidden. For Example, whenever we are about to send an email, we just type the content to be sent and click upon send button to send the mail. But, we are not supposed to see the internal processing about the email delivery, that’s its beauty. Therefore, Abstraction lets you focus on what the object does instead of how it does it.

Ways to achieve Abstraction:

There are two ways to achieve abstraction in java. They are:

  • Abstract Class
  • Interface

Let’s consider it with an example:

Using Abstract Class:

Using Interface:


2. Encapsulation

Encapsulation is subset of Abstraction. It is a technique used to implement abstraction concept. Encapsulation means hiding the code and data into a single unit to protect the data from outside world. It is a way of keeping some part of data private by allowing no access to it from outside. It is also known as Data Binding.

Ways to Achieve Encapsulation:

Encapsulation in java achieved using:

  • Access specifiers such as private, protected and public keywords.
  • setter and getter methods

Let’s take an example:

3. Polymorphism

Polymorphism word itself mean that ‘capability of representing one form in multiple forms’. Any object in Java that passes more than one IS-A tests is said to be polymorphic in nature. Generally in Java, all objects are polymorphic in nature. Since, any object will pass minimum of two tests: one for itself and one for Object class.

An important usage of polymorphism occurs in oops is how a parent class refers to a child class object.


Suppose if a person is at home, he behaves like a son to his parents. If he is in class, behaves like a student. So, here single person behaving in different forms.

Polymorphism in java has two types. They are:

  • Static Binding(Compile Time Polymorphism)
  • Dynamic Binding(Run Time Polymorphism)

Static Binding:

Static Binding also known as Method overloading/Compile-Time Polymorphism. Same method name is overloaded with different number of parameters in same class with different signature. In this mechanism overloaded method calls get resolved at compile time by the compiler.

Let’s us take a simple example:

Dynamic Binding:

Dynamic Binding also known as Method overriding/Run-Time Polymorphism. Same method is overridden with same signature in different classes.  In this Mechanism overridden method call get resolved at Run-Time.

Let’s look it with an example:

4. Inheritance

Inheritance is one of the features of object oriented programming. It is a concept which allows to use properties and methods of one class in another. In other words, properties and behaviors from the base class is inherited into derived class. The class from which properties are inherited can be called as Super class or base class and class which inherits properties of base class can be called as Subclass or derived class.

Additional attributes and methods can be added by derived class. A super class can have any number of sub classes, but not vice-versa.

In order to inherit properties of base class by derived class, java offers extend keyword as shown below:

Types of Inheritance:

  • Single Inheritance
  • Multi Level Inheritance
  • Hierarchical Inheritance

Related Posts