Java is class based programming language built around the concept of object. OOP concept are invented to improve the reusability and readability of program. The key concepts of OOPS are as per below:

1. Abstraction

2. Encapsulation

3. Inheritance

4. Polymorphism

What is oops?

Object-oriented programming System. Object could be anything it could be Pen, Table, Book etc.

OOP concepts allow us to create specific interactions between Java objects. They make it possible to reuse code without creating security risks or harming performance and code readability.

There are four main and three secondary principles of object-oriented Java programming. Let’s take a look at what they are and why they’re useful.

1. Abstraction

Abstraction is process of hiding the functionality from user. For example car, We can drive car we all knows the use of break, steering, Accelerator etc. but we don’t know the functionality of that part. Abstract is a keyword in java. We can declare Abstract method, Abstract Class. The method which don’t have body is called abstract method.


  • Abstract method must be written inside the abstract class. But if class is abstract it is not compulsory that all methods should be abstract.
  • If we inherited the abstract class then we must have to override abstract methods which declared inside parent class. Otherwise it will give error.
  • We can not create object of abstract class because we can write abstract method inside abstract classes. Abstract method dont have body so we cant create object of abstract class.

2. Encapsulation:

It is mechanism of wrapping the data (Variable) and code acting on data (Method) together as single unit.

step to achieve Encapsulation:

  1. Restricts direct access to data members (fields) of a class
  2. Fields are set to private
  3. Each field has a getter and setter method
  4. Getter methods return the field
  5. Setter methods let us change the value of the field

3. Inheritance

Inheritance makes it possible to create a child class that inherits the fields and methods of the parent class. The child class can override the values and methods of the parent class, but it’s not necessary. It can also add new data and functionality to its parent.

Parent classes are also called superclasses or base classes, while child classes are known as subclasses or derived classes as well. Java uses the extends keyword to implement the principle of inheritance in code.

Inheritance in Java:

  • A class (child class) can extend another class (parent class) by inheriting its features
  • Implements the DRY (Don’t Repeat Yourself) programming principle
  • Improves code reusability
  • Multi-level inheritance is allowed in Java (a child class can have its own child class as well)
  • Multiple inheritances are not allowed in Java (a class can’t extend more than one class)

Abstraction, encapsulation, polymorphism, and inheritance are the four main theoretical principles of object-oriented programming. But Java also works with three further OOP concepts: association, aggregation, and composition. Aggregation is a special form of association, while composition is a special form of aggregation. While that may sound a bit convoluted, we’re about to explain. Read on!

4. Polymorphism

Polymorphism refers to the ability to perform a certain action in different ways. In Java, polymorphism can take two forms: method overloading and method overriding.

Method overloading happens when various methods with the same name are present in a class. When they are called, they are differentiated by the number, order, or types of their parameters. Method overriding occurs when a child class overrides a method of its parent.

Polymorphism in Java:

  • The same method name is used several times
  • Different methods of the same name can be called from an object
  • All Java objects can be considered polymorphic (at the minimum, they are of their own type and instances of the Object class)
  • Static polymorphism in Java is implemented by method overloading
  • Dynamic polymorphism in Java is implemented by method overriding

image credit:

One thought on “Using OOP concepts to write high-performance Java code”
  1. Hello there, I found your site via Google at the same time as looking for a comparable topic, your web
    site came up, it appears to be like good. I have bookmarked it in my google bookmarks.

    Hello there, simply become alert to your blog thru Google, and located that it’s really informative.
    I’m going to watch out for brussels. I will appreciate if you happen to proceed this
    in future. A lot of other people can be benefited from your writing.

Leave a Reply

Your email address will not be published. Required fields are marked *