Java OOPs Concepts: Encapsulation, Abstraction, Inheritance, Polymorphism

07 Feb 2023

Java OOPs Concepts: Encapsulation, Abstraction, Inheritance, Polymorphism

Object-oriented programming is one of the most important features in the development field. Object-oriented programming was created in the year 1970. Let's understand the idea of object-oriented programming in this article

What is the OOPs Concept?

Object-oriented programming is one of the fundamental concepts of programming that helps developers to bind functions and data together with the help of objects and classes. The OOPs concept in Java assists the programmers how to control and access the data and implement this for improving the readability and reusability of the code.

In Java, every class has some objects. Every object has some methods and properties associated with them. After combining them it will build the structure of object-oriented programming. For instance, a "class", named "human" can have an "object" as a "name". This "name" object can store the "email id", and "phone number" of a person, and the "methods" here, will help to send mail or call.

The OOPs concept in java depends on the 4 core concepts, which are Abstraction, Inheritance, Encapsulation, and Polymorphism.

What are classes and objects in Java?

Classes in oops concepts in Java are "local entity" that does not require any memory space without the object. It is a blueprint of Java programming. In Java "class" keyword is used to declare a class such as objects, methods, variables, etc that are situated inside the class. For instance, an architectural drawing of a building is called a blueprint as well as it can be called a "class" and the building that is created according to the blueprint is called an "object".

The class represents the working and structure of an object by using variables and attributes of the data and the method or the member functions. Data attributes assist to define the member functions in Java.


<access-modifier> class <className>
  // data attributes;
  // member functions()

A class consists of some elements that are

  • Class: it defines the particular class
  • Access Modifiers: it defines if the class should be "public", "private", "package-level (default)" or "protected".
  • Class Name: Give a name to the class
  • Superclass: it mentions the name of the superclass if there are any
  • Interface: Mentions the name of the super interface if there is any
  • Body: it represents the body of the class with {} these curly braces.

Fundamental Pillars of OOPs Concept

There are four fundamental Pillars of the OOPs Concept in Java, which are

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

Encapsulation in Java

Encapsulation in Java is one of the features of OOPs that helps in binding and wrapping the information about the data in a single unit. It gives the highest security to the data by hiding the detailing about the implementation from users. It allows the user to access a particular level without giving them the complex details behind it by doing the declaration of the object privately.

As an example, we can choose "Herbivorous animal" as a class. So all the animals that eat plants are situated under this category. Cows, Goats, and Deer these animals that encapsulate this particular category of the food chain.

For another example, we can choose any banking services application and how encapsulation helps to understand the related problems. In the application, we can consider any class that can be accessed by the customer such as they can change or modify their profile or password. Here, a profile or password works as an object in the class. But for maintaining privacy the developers ensure that the password net gets published by encrypting the object of the class.

Abstraction in Java

Data abstraction is a unique feature of object-oriented programming, that is primarily used for hiding the details of implementation from users. It only shows important information to the users. In Java, programmers use the concept of interfaces and abstract classes for achieving data abstraction.

As an example, we can choose a database that contains information about students. If someone wants to fetch any information such as name or score greater than 70 the query fetches the information. The shows the data accordingly but hides the elaborated information.

Inheritance in Java

Object-oriented programming has one significant feature, called Inheritance. In this method, one particular class, which is a child class, inherits the property of the other superclass. It helps to boost the reusability of the property of the code in a Java program. Inheritance has two different classes, which are

  • Child or Subclass: it inherits the properties of a superior class
  • The parent or Superclass: the properties of this class inherited by subclasses

There are three types of Inheritance in Java

  1. Single Inheritance: This is a single level Inheritance with one subclass with the properties of super class
  2. Hierarchical Inheritance: it multiplied one parent class with child classes
  3. Multilevel Inheritance: if there are 3 classes named A, B, and C then class B inherits the properties of class A and class C inherits the properties of class B

Polymorphism in Java

Polymorphism demonstrates a single entity can have multiple forms in object-oriented programming. For instance, a person can be a student or a Millionaire. 

There are two types of Polymorphism, such as

  1. Compile-time Polymorphism- is used for expressing the overloading in Java programming
  2. Run-time Polymorphism- it is used for expressing overriding.

Advantages of OOPs Concept

  • Using object-oriented programming in Java enhances the readability and reusability of the code and saves development time
  • Method like Inheritance in OOPs concepts eliminates the importance of code redundancy
  • It builds easy communication between objects and classes
  • It gives the highest security by using functions like data abstraction and hiding
  • It is easy maintenance as the modules of OOPs are very flexible

Disadvantages of OOPs Concept

  • Program size in OOPs is much larger than in other methods
  • It requires much knowledge and effort to create a perfect OOPs-based code
  • It executes at a slower time than other methods.


This article gives a proper idea of what is OOPs in Java and the OOPs principle in Java. So, these were some of the features of OOPs and OOPs concepts in java that you must know if you wish to pursue a career in Java programming. Of course, there are many other such concepts too but these are the ones that form the base of this programming language. I hope this article was helpful and informative enough for you and that it taught you something new today. If not, please let me know what else you would like to learn about Java programming in the comments section below and I shall make sure to cover it in my next article. Thank you for reading!

Accept cookies & close this