RAKESH KUMAR SINGH
3 min readMay 9, 2021

--

Object Oriented Programming :

OOP stands for Object-Oriented Programming. In procedural programming we create procedures or methods that perform operation on data , it becomes highly complex when we use procedural programming on large application , there was lot of security issue then after object oriented programming came where we deal with everything in the form of class and object.

Object and Classes :

Classes and object are two main aspects of object oriented programming. For understanding about object and classes we can think object as a real world entity and class as a template for object. for example let say Car is a class and any particular car such as audi , toyota will object of Car class. When any objects are created, they inherit all the variables and functions from the class.

Important concepts in OOP :

Encapsulation: It is the mechanism by which we place all variable and methods of any class at one place. In another way we can say that it is a protective shield that prevents data from outside access. We can achieve encapsulation by declaring each member variable as private and define method in public mode for reading and writing that variables. In this way we can restrict direct access of data of class. we need this type of implementation in many cases in our real life such as bank account.

Abstraction: It is the property by which we only show the essential detail to the user and we hide implementation detail or non-trivial things such as let say we are driving car and in car we only know which component is responsible for which task we don’t know how that component is working ,that is abstraction. In java abstraction is achieved by interfaces and abstract class because in interfaces we only declare methods and variable and implementation of methods is written in class who implemented that interface.

Difference between abstraction and encapsulation: In encapsulation information is hided but in abstraction implementation is hided by use of interfaces as explained above.

Inheritance : It is the most important pillar of object oriented programming. It is the mechanism in java by which one class is allowed to inherit the properties and method of other class. By inheritance we can avoid writing same code many times as when we want to create a new class and there is already a class that includes some of the code that we want, then we can derive our new class from the existing class.

e.g -

class Person {
String name = “rakesh”;
int age =24;

}

class Rakesh extends Person {
public static void main(String args[]){
Rakesh obj = new Rakesh();
System.out.println(obj.name + obj.age);
}
}

In above example we can see there is a class named Person which has property name age and we declare another object named Rakesh which extends Person class . In object of Rakesh class we can use variable name and age directly by the help of inheritance.

Polymorphism: It is one of the most important feature of object-oriented-programming. Polymorphism allows us to perform a single action in different ways. In our real life also a person can have more than one characteristic at the same time , same person can behave as father or husband, this is called polymorphism.

In Java polymorphism is mainly divided into two types:

Compile time polymorphism : This type of polymorphism is achieved by method overloading. This is static polymorphism means when we define more than one method by the same name then which method will be executed is decided at compile time.

Run time polymorphism : This type of polymorphism is achieved by method overriding. In run time polymorphism we define different version of same method with same name and which method will executed is decided at run time.

--

--