In this chapter we will discuss OOPs concepts available in Java. Let’s get started.
Entity that has the state and behaviour is known as an object. An object can be defined as the instance of class. As Java is an Object-oriented programming language, we create objects to get the job done. Objects consume some space in memory. Objects can communicate without knowing the details of each other’s code. The only thing is the type of input accepted and the type of response returned by the objects.
A class is a collection of objects. Class does not consume any space. It acts as an object constructor or ‘blueprint’ for creating objects.
It is defined as the process where one class acquires the properties of another. The class which inherits the properties of another is called a derived/subclass. The class whose properties are inherited is called as a parent class/ super class. Inheritance provides code reusability.
Polymorphism means ‘many forms.’ It means one task can be performed in different ways. In Java, we have method overriding and method overloading to achieve polymorphism.
We can achieve Abstraction by using the abstract class and interface. Abstraction is defined as showing functionality by hiding internal functionality.
Encapsulation is a fundamental concept of OOP. Binding data and code as a single unit is known as Encapsulation. A class in Java is an example of encapsulation.