Object Oriented Programming in Java

Chamika Madhushan
2 min readJun 17, 2023

--

Object oriented paradigm is based on objects which mimics real world entities.

Classes and Objects are main components of OOP concept.

Source https://javatutorial.net/java-oop

What is a class ?

Class is a blue print or a template to create objects.

As in the above picture Car is a class. It is just a logical entity.

Classes have behaviors(or methods) and attributes (or fields) that related to common characteristics and common functionalities of the class.

What is an object ?

Object is an instance of a class.

Objects mimic real world entities.

If Car is a class we can create instances such as Audi, Nissan, Volvo.

Behaviors and attributes of the class are specified in the object (considering the real world entity).

What is an attribute ? (field)

Attributes are the characteristics of the class that help to distinguish it from other classes.

It is a named property of the class. It describes the range of values that that property may hold.

Car class may contain attributes like color, capacity, model, number of seats etc.

What is a behavior ? (method)

Behaviors are the actions performed by the objects of the relevant class.

Behaviors of an object are defined as methods. These methods determine what type of functionality a class has, how it modifies its data, and its overall behavior.

Objects of car class may have methods such as Start(), Drive(), Stop(), FuelRefill(fuel) etc.

Car Class can be created as below.

Car Class

Objects of the car class can be created as below.

Objects of car class

There are four main principles of OOP in java

Source https://www.thejavaprogrammer.com/4-pillars-of-oops-in-java/
  • Abstraction.
  • Encapsulation.
  • Inheritance.
  • Polymorphism.

--

--