top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

OOPs concepts in JAVA

Updated: May 1, 2025

OOPs stands for Object Oriented Programming.


Java is a popular programming language designed to be platform independent , meaning its code can run on different operating systems without modifications. Java programming language is created in 1995 by Sun Microsystems.


It is a Object Oriented Programming language which is the most widely used for software development. In this article , we will cover Object Oriented programming concepts in JAVA.


Object Oriented programming has several advantages:


  • OOPs is faster and easier to execute.

  • OOPs provide clear structure of program.

  • OOPs helps to keep Java code easier to maintain , modify and debug.

  • OOPs make it possible to create full reusable applications with less code and shorter development time.


Java Object Oriented Programming (OOPs) Concepts:


  1. Class

  2. Object

  3. Encapsulation

  4. Abstraction

  5. Polymorphism

  6. Inheritance


  1. Class :


    Class is nothing but the user define data type. Class is a collection of data types , methods, constructors etc. Its like a blue print of objects. Also we can say Class is template for objects.


Example of Class



In above example there is Student class created with the properties like "roll_number " and "Std_Name" and "print()" method. So here we have created one blue print of student.


If you want to create a class for student , In that case "Student" will be class and student records (like objStd1, objStd2 , etc )will be the objects. We can also consider that class is a factory to produce objects.



  1. Objects :

In objects oriented programming , an object is an entity that has two characteristics (state and behaviour) . Some of the real-world objects are book, mobile, car, table etc. An Object is variable of type class . With the help of objects we can access the properties and methods of that class.


Example of Object



In above example you can see , we have created objects for 4 students like "objStd_1, objStd_2 etc. .See the output below.


Output


  1. Encapsulation :


Encapsulation means binding a data into a single unit like class. Here we can restrict a direct access to the important data.


Example of Object



Here we declared the variables as a private ,so you can restrict the direct access.


4. Inheritance :


In object oriented programming , Inheritance is the process of creating a new class from old class. So new class is called as derived class and old class is called as base class. It is like a parent child relationship , where we can access the properties of parent class (base class).


Type of Inheritance :


Single Inheritance : Refers to a parent child relationship where a child class extends the parent class features. Class Y extends Class X.


Multilevel Inheritance : Refers to a parent child relationship where a child class extends another child's class. Class Y extends Class X. And Class Z extends Class Y.


Hierarchical Inheritance : This refers to a parent child relationship where several child classes extends one class. Class Y extends Class X. And Class Z extends Class X.


Multiple Inheritance : Refers to a parent child relationship where a one child class is extending from two or more parent classes . Java does not support multiple Inheritance.



  1. Abstraction:


    In object oriented programming , Abstract means providing only the necessary data and hide the background details or functionality.We can use abstract keyword before the method or before the class to declare it as a abstract.We can not create object of abstract class.The real world example of abstraction is Car, the internal details such as engine, the process of starting a car, etc. are hidden from the users.


Purpose of Abstraction :


Simplification : Abstraction allows developers to work with complex systems by simplifying the interaction with them.


Code reusability : By defining common interfaces , abstraction promote code reusability across different implementations.


Enhanced security : It hides the internal implementation details thus protecting the code from unauthorised access and modifications.

Example of Object both concepts Inheritance & Abstraction :

The above example is the implementation of inheritance and abstraction. Implementation of abstraction is possible only with the inheritance.


  1. Polymorphism :


Polymorphism meaning "many forms", is a core concept in object oriented programming that allows objects of different classes to be treated as objects of common type . In Java , polymorphism is primarily achieved through method overloading ( Compile time polymorphism ) and method Overriding ( Run Time Polymorphism).


1. Method Overloading

2. Method Overriding


  1. Method Overloading (Compile time polymorphism ): It means, In a single class there are two methods with the similar name but there parameters are different


  2. Method Overriding (Run time polymorphism) : It means , similar name of methods present in two different classes and there parameters are also same.


Example of Method Overloading



Example of Method Overriding


Difference between Method Overloading and Method Overriding



Method Overloading

Method Overriding

Method overloading is a compile-time polymorphism.

Method overriding is a run-time polymorphism.

Method overloading helps to increase the readability of the program.

Method overriding is used to grant the specific implementation of the method that is already provided by its parent class or superclass.

It occurs within the same class or across different classes.

It is performed in two classes with inheritance relationships.

In method overloading, methods must have the same name but different signatures.

In method overriding, methods must have the same name and the same signature.

Method overloading does not require inheritance.

Method overriding always needs inheritance.

The argument list should be different while doing method overloading.

The argument list should be the same in method overriding.

Private and final methods can be overloaded.

Private and final methods can’t be overridden.

Static binding is used for overloaded methods.

Dynamic binding is used for overriding methods.

In method overloading, the return type can or can not be the same, but the parameter list must differ.

In method overriding, the return type must be the same or covariant.


Thanks for reading the blog! Hope you found it helpful - Happy learning!

+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page