Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconData Science USbreadcumb forward arrow iconOOPS Concepts Explained for Beginners

OOPS Concepts Explained for Beginners

Last updated:
19th Dec, 2022
Views
Read Time
8 Mins
share image icon
In this article
Chevron in toc
View All
OOPS Concepts Explained for Beginners

The role of computer programs is to successfully model complex real-world requirements into computer-understandable instructions. To accomplish that, several programming paradigms work on different philosophies. These include Functional Programming, Procedural Programming, Object Oriented Programming, and more. These paradigms differ based on how they work and are therefore language-independent. 

In this article, we’ll look at Object Oriented Programming in depth. Before we get into the complexities of OOPS, here are some key OOPs concepts in Java that you should keep in mind, as they are the four pillars on which OOPS works: 

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism

We’ll talk about these OOPs concepts in depth at a later stage in this article. But first, let’s understand what exactly is Object Oriented Programming. 

What is Object Oriented Programming?

Before Object Oriented Programming, Functional Programming was the dominant programming paradigm. Languages like C and COBOL followed this paradigm, so the programs written using these languages were a series of instructions. These used subroutines or procedures to keep the source codes modular and more readable. The Functional Programming paradigm focused more on logic than data, and the program would combine both the data and program. 

Ads of upGrad blog

Programming languages, like C++, C#, Java, and more, moved on to the Object Oriented Programming approach after C. OOPs prioritized data overwriting simple logic-based instructions. In essence, an object is anything that you want to model in your program. It could be anything and everything. If it sounds vague right now, stick till the end, and you’ll understand exactly what we mean by this! 

What are Classes and Objects? 

Object Oriented Programming works with Classes and Objects. So, it’s important to understand what these two terms mean and how they are different from one another. Simply put, think of Classes as a blueprint that helps create Objects as and when you need them.

The role of Classes is to define various attributes and different behaviors. So, if we were to model a vehicle in our program, we would make a Class for the vehicle and keep attributes such as the number of wheels, color, model, age, and so on; whereas the behaviors would be like start, accelerate, brake, and so on. As you can see, the attributes and behavior we have defined are not specific to one vehicle. They essentially encompass the different behavior and attributes across different vehicles. That way, when you want to instantiate a new vehicle object, you can specify the attributes per the vehicle in question. In this way, Classes act as a perfect blueprint for creating new objects with the same attributes and behaviors.

So, here is what our Class Vehicle and its different attributes and behaviors will look like. Remember that we’ve used Java’s syntax to write the code, but the programming paradigm is language-neutral. 

public class Vehicle{

private string _color;

private int _model;

private string _makeYear;

private string _fuelType;

public void start(){ }

public void accelerate() {}

public void stop() {} 

}

Using the defined Class, we can create various objects with different attributes while having common behaviors. For instance: 

Object 1
ModelAlto
FuelCNG
Make2018
Start()

Break()

Accelerate()

Object 2
ModelWagonR
FuelPetrol
Make2017
Start()

Break()

Accelerate()

This way, Classes in Object Oriented Programming can help you simplify modeling real-world complex behaviors and systems. All the data, attributes, and functions are bound to the object of any class. This way, the need to keep any global data is eliminated. This is an important difference between Procedural Programming and Object Oriented Programming approaches. 

With the basics settled, let’s look at the four pillars of Object Oriented Programming in depth:

Get data science certification from the World’s top Universities. Learn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Abstraction

Abstraction is all about focusing on what is done instead of how the task is performed. The whole idea behind abstraction is to help build independent modules which can be made to interact with one another without having any other reliance on one another. This way, the maintenance of a program also becomes easier and more manageable. With Abstraction, OOPs try to represent only essential features without going into how those features are implemented or how the system’s internals work. 

The idea behind one of the most important OOPS concepts in Python is that programmers need to focus only on the things that matter to the current module directly. Modifying one module should not directly impact other independent modules. A programmer only needs knowledge of the current module and what it gives. There is not much need to understand the background workings of the module to accomplish what is required; therefore, that information is abstracted out for best results. 

If you take the idea of abstraction beyond programming, you will realize that abstraction, in essence, is everywhere. The objects we deal with daily are abstracted from us at various levels. For example, we don’t know how our car brake’s internals work, but we have been provided with a pedal to apply brakes while abstracting the mechanism behind the curtains. That way, you don’t need to worry about how it works; you just need to press the pedal. 

Encapsulation

The encapsulation concept is closely tied to the previous concept of abstraction. Encapsulation is, in essence, all about providing the solution to a problem without requiring the end user to understand the domain of the problem fully. For doing this, encapsulation binds all the data and behavior together as a single unit. That way, the end-user is prevented from knowing about the inner elements wherever abstraction is implemented. 

The user cannot access the data directly and uses exposed functions to access the data as and when needed. By hiding the object’s internals, the OOPS programming paradigm protects the integrity of the modules and doesn’t allow users to set the internal data into an inconsistent state. If not done, this could cause many problems in the long run. So, in this way, encapsulation is more about exposing complexity in a failproof manner and less about completely hiding complexity. 

Inheritance

Inheritance is another powerful feature of the Object Oriented Programming paradigm. The role of inheritance is to efficiently and quickly arrange and organize classes into a hierarchy to enable these classes to inherit behavior and attributes from classes that lie above in the hierarchy. In essence, inheritance can be understood as an “is a relationship”, which is very similar to how we talk about things in the real world. 

For instance, we say that “a parrot is a bird”. That means that a parrot is an object of the class bird, and so it inherits some attributes and behaviors from the broader class. However, that won’t be correct if we say that a bank is a bank account. That is how the hierarchy in inheritance works, and it lets you define behaviors and implementations that can be later specialized for specialized classes. Keep in mind that inheritance doesn’t work backward. So, the parent class will never inherit anything from the child class. However, child classes inherit both attributes and behaviors from parent classes, depending on the nature of those attributes and behaviors (public or private). Inheritance is a way to reuse your program and can help you make your entire source code shorter and much more understandable. But you must remember that you shouldn’t go around adding levels after levels of inheritance if it isn’t needed. 

Check our US - Data Science Programs

Polymorphism

Polymorphism is one of the many important OOPS concepts in Python and Java, which essentially takes care of many different possible implementations of any executable units and all the subtle differences that go on in the background without making the user aware of those changes. Polymorphism makes it easier for computer programs to be extended with specialized objects without any difficulty. 

For instance, if you wish to write a piece of text on paper – you could use a pen, a marker, a crayon, or even a pencil. All you need is something that can fit in your hand and help you make symbols as you press it against a paper. So, the act of writing will help you make symbols on paper, whereas what instrument you require depends on your choice. 

Ads of upGrad blog

In this sense, inheritance is a way for the program to achieve polymorphism, wherein the custom implementation of the method overwrites the behavior defined in the inherited class. This process is also known as run-time polymorphism or method overriding. There is another form of polymorphism, also known as method overloading. In that, inheritance does not come into the picture at all. In method overloading, the method name is kept the same, whereas the arguments in the method differ based on what task is to be performed. 

In conclusion

With that, we come to the end of our discussion on OOPS concepts in Java. The things discussed so far set all the foundation you require to get started with Object Oriented Programming without worrying about anything. You must implement the discussion and try things hands-on; after all, programming is all about practicing and persevering. 

The knowledge of OOPS will help you in your data science journey, too, as you will be using languages like Python, which relies on the OOPS paradigm. Data Science is a booming field, and there is no dearth of opportunities for people with the right skills and knowledge. Check out our MS in Data Science by upGrad, in collaboration with the University of Arizona, and get a chance to learn from industry experts alongside a strong network of alumni that will help you throughout your career. 

Profile

Pavan Vadapalli

Blog Author
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and long term technology strategy.
Get Free Consultation

Select Coursecaret down icon
Selectcaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Best Data Science Courses

Frequently Asked Questions (FAQs)

1What are the four concepts of OOPS?

The four core concepts of OOPS are Abstraction, Encapsulation, Inheritance, and Polymorphism.

2 How do classes and objects differ?

Classes are the blueprints of the phenomena that are to be modeled. Objects, on the other hand, are particular instances of classes that borrow behavior and attributes from the class they are instantiated from.

3What language does OOPS work on?

OOPS is a programming philosophy that is language-neutral. You can work on OOPS using any modern-day programming language like C++, Java, Python, Ruby, etc.

Explore Free Courses

Suggested Blogs

Top 10 Real-Time SQL Project Ideas: For Beginners & Advanced
15028
Thanks to the big data revolution, the modern business world collects and analyzes millions of bytes of data every day. However, regardless of the bus
Read More

by Pavan Vadapalli

28 Aug 2023

Python Free Online Course with Certification [US 2024]
5519
Data Science is now considered to be the future of technology. With its rapid emergence and innovation, the career prospects of this course are increa
Read More

by Pavan Vadapalli

14 Apr 2023

13 Exciting Data Science Project Ideas & Topics for Beginners in US [2024]
5474
Data Science projects are great for practicing and inheriting new data analysis skills to stay ahead of the competition and gain valuable experience.
Read More

by Rohit Sharma

07 Apr 2023

4 Types of Data: Nominal, Ordinal, Discrete, Continuous
6155
Data refers to the collection of information that is gathered and translated for specific purposes. With over 2.5 quintillion data being produced ever
Read More

by Rohit Sharma

06 Apr 2023

Best Python Free Online Course with Certification You Should Check Out [2024]
5640
Data Science is now considered to be the future of technology. With its rapid emergence and innovation, the career prospects of this course are increa
Read More

by Rohit Sharma

05 Apr 2023

5 Types of Binary Tree in Data Structure Explained
5385
A binary tree is a non-linear tree data structure that contains each node with a maximum of 2 children. The binary name suggests the number 2, so any
Read More

by Rohit Sharma

03 Apr 2023

42 Exciting Python Project Ideas & Topics for Beginners [2024]
5900
Python is an interpreted, high-level, object-oriented programming language and is prominently ranked as one of the top 5 most famous programming langu
Read More

by Rohit Sharma

02 Apr 2023

5 Reasons Why Python Continues To Be The Top Programming Language
5340
Introduction Python is an all-purpose high-end scripting language for programmers, which is easy to understand and replicate. It has a massive base o
Read More

by Rohit Sharma

01 Apr 2023

Why Should One Start Python Coding in Today’s World?
5224
Python is the world’s most popular programming language, used by both professional engineer developers and non-designers. It is a highly demanded lang
Read More

by Rohit Sharma

16 Feb 2023

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon