Object Oriented Programming in Java

In this post, We will see about what is Object Oriented Programiming and how it is used in Java

What is Object Oriented Programming (OOPS)

Object Oriented Programming is based on the concept of “Objects”. Real world objects have unique features and behaviour. Characters are called properties in Java and behaviors are called methods. Objects are defined using the keyword “class”. Objects are created using Class. The programming using classes and objects are called Object Oriented Programming.

Reusable, scalable, extensible, refactoring, efficiency and easy maintenance are the benefits of Object Oriented Programming. Object oriented programming is easy to debug and fix bugs compared to linear programming. Data and method separation is not susceptible to such multiple errors.

What is Class?

A class can be defined as a template that determines what is contained in the object and how the object acts. A class is an object blueprint.

What is an Object?

An Object is an instance of a class. Objects have states and behavior. For example, car is an object with state such as color, length, width, height, etc. and behavior such as starting engine, stop engine, accelerate, break and change gear.

What are OOPS Concepts?

Object-oriented programming is commonly known as OOPS. It contains four basic concepts referred to as

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

What is Abstraction?

Abstraction means that only essential and relevant details are exposed by hiding interiors and low level details. For example, a driver can use the start button and the stop button. When a driver starts a car, how the engine starts is hidden to the driver.

What is Encapsulation?

Encapsulation encapsulates the data and code. If two objects are created using a single class, separately maintained states and behaviors of two objects. Changing an object’s state does not affect another object. For example, if you buy two cars with the same model from the same company, the two cars must be operated separately.

What is Inheritance?

Inheritance is a process of acquiring state and behavior of parent class to child classes. For example, The vehicle is parent class and Car & Bike are child class. The vehicle has wheels, engines and can start and stop. Car & Bike are vehicles that can inherit vehicle states and behavior. Car and Bikes cah have additional state and behavior.

What is Polymorphism?

Polymorphism means a lot of shapes. In different programming contexts, a single object acts differently. For example, tolls are collected for vehicles. Car & Bike are vehicle. The toll charge is calculated differently depending on which vehicle is entered.

Related Articles

Leave a Reply

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