Trusted answers to developer questions

What is Object-Oriented Programming?

Get Started With Machine Learning

Learn the fundamentals of Machine Learning with this free course. Future-proof your career by adding ML skills to your toolkit — or prepare to land a job in AI or Data Science.

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

RELATED TAGS

object-oriented design
beginner
templates
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?