What is Object-Oriented Programming?

An “Object” is the key component of Object-oriented programming. An Object may contain data (fields or variables) or code (methods or procedures). The creation of these objects is based on a programmer-defined blue-print also known as a Class.

Classes are like ideas. Objects are concrete manifestations of those ideas.

An example of classes

svg viewer

Java is an example of an Object-oriented programming (OOP) language.

The four basic principles of OOP

svg viewer
1) Inheritance

Inheritance is the process of creating new classes, called derived classes, from base classes where an “is-a” relationship exists. The derived class extends from the base class in order to inherit its properties.

2) Polymorphism

Polymorphism is the ability of an object to take on many forms. For example, square, rectangle, circle and triangle classes can have the same parent class Shapes, but each class can have its own method named drawShape().

Shapes Class is a perfect example of polymorphism
Shapes Class is a perfect example of polymorphism
svg viewer
3) Abstraction

Abstraction in OOP refers to showing only the essential features of an object to the user and hiding the other details to reduce complexity.

4) Encapsulation

Encapsulation in OOP refers to binding the data and the methods to manipulate that data together in a single unit (class). This is normally done to hide the state and representation of an object from outside.

svg viewer
Copyright ©2024 Educative, Inc. All rights reserved