Geeks logo

OOPS: Easier way to Understand

Concepts explained in simple terms

By Arun RamasamyPublished about a year ago Updated about a year ago 6 min read
2

OOPS stands for Object-Oriented Programming Concepts using which famous programming language like C++, Java, Scala are build upon.

OOPs interview questions are a crucial aspect to consider when preparing for a software engineering interview,

as they test a candidate's understanding of object oriented programming concepts and their ability to implement them in real-world scenarios.

In this article, we can discuss on how to make it easier for beginners or novice users or even a kid to understand oops concept. The main concepts of OOPS include:

Encapsulation:

Encapsulation is a technique in object-oriented programming that allows you to protect the data within an object from being accessed or modified by code outside of that object. It's like a protective wrapper around the data that keeps it safe and secure.

For example, imagine you have a bank account object that contains information such as your account number, balance, and transaction history. The encapsulation concept would be applied by making the account number and balance private so that they can only be accessed or modified through specific methods within the bank account object. This way, if you want to check your balance or make a withdrawal, you would use the appropriate methods provided by the bank account object, rather than trying to access the data directly.

Another example could be a car object, it has various properties such as speed, gear, and fuel level. Car object encapsulate these properties and provide methods to access and modify these properties. For example, instead of directly accessing the speed property, you use the accelerator method to increase the speed and brake method to decrease the speed. This way the actual implementation of how speed is being increased or decreased is hidden from the outside world, providing a secure and reliable way of controlling the car.

Polymorphism:

Polymorphism means something can take on many different forms. Think of a chameleon, it can change its color to blend in with its surroundings. Similarly, in computer programming, one piece of code can be used for different types of data or objects. This makes the code more flexible and reusable.

For instance, think of a shape. A shape can be many things like a square, a triangle, or a circle. Each shape has its own unique properties and behaviors, but they can all be referred to as just "shapes." So, when we write code to draw a shape, we don't have to write separate code for each different type of shape, we can use one piece of code that can handle all of them. This is polymorphism.

Another way to think of it is like a remote control. A remote control can change the channel on different TV's but the button you press is the same for all TV's, that's polymorphism.

Inheritance:

Inheritance is like getting something from someone else. Imagine you have a toy box, and inside the toy box there are many different types of toys like cars, dolls, and balls. Each toy is special and has its own unique features. Now, imagine you have a new toy that is a race car. The race car is a special type of car that can go faster than the other cars in the toy box. But it still has many of the same features as the other cars, like wheels and doors.

In programming world, this is similar to how inheritance works. We have a "parent" class that has certain features and behaviors, and then we have a "child" class that inherits those features and behaviors but can also have its own special features. This way, we don't have to write the same code over and over again for each different class, we can just inherit the common features from the parent class.

An easier way to think of it is, assume you have a big brother, you have learned many things from your big brother,

like riding a bike, playing football and swimming. These are the things that you have inherited from your big brother, and you can use them in the same way he does.

Abstraction:

Abstraction is like looking at something from a distance and focusing on the most important parts. Imagine you are looking at a big building from far away. You can see that it is big and has many different parts, like windows, doors, and a roof. But you don't need to know all the details about how the building is made or how it works, you just need to know that it is a building and it serves a purpose.

In computer science, abstraction is similar. We want to focus on the most important parts of a program and hide the details that are not important. This makes the code easier to understand and use. For example, when you use a cell phone, you don't need to know how it works on the inside, you just need to know how to make a call or send a text message. The internal details of how the phone works are abstracted away, so you can use it easily.

A simpler way to think of it is, imagine you are using a vending machine to buy some snacks. You don't need to know how the vending machine works on the inside, all you need to know is how to select the snack you want and insert the coin, the rest is abstracted away, the process of getting the snack from the vending machine.

Classes & Objects:

A class is like a blueprint for something. Imagine you want to build a toy car. You would have a blueprint that shows how to put all the pieces together, like the wheels, the body, and the steering wheel. The blueprint tells you what pieces you need and how to put them together. But it's not a real car yet, it's just a plan.

Similarly in programming, a class is a blueprint for an object. The class defines what the object should look like and what it should be able to do. But it's not a real object yet, it's just a plan.

An object is like a toy car that you built using the blueprint. Now that you have all the pieces together, you can play with it. It's a real thing that you can use and interact with.

In computer programming, an object is a real thing that you can use and interact with. You create an object by using the blueprint (class). So, if you have a class called "Car", you can create a new object that is a specific car, like a "red sports car" or a "blue sedan car". Each object created from the same class will have their specific properties, but they all have the same capabilities as defined in the class.

Another way to think of it is, imagine you are a kid and you are playing with toy blocks. The blocks come in different shapes and colors. The blocks are the objects and the different shapes are the classes. The blocks of the same shape can be used to build different things, but they all have the same capabilities, like fitting together and stacking.

The concept of OOPs can be easily taught to people who have zero knowledge of programming, by comparing each concept with real world entities.

Happy Programming !!!!

featureinterviewindustryhow to
2

About the Creator

Arun Ramasamy

Nature Lover, Just go with the flow, techno freek.

Do what you can.. don't when you cannot.

Reader insights

Be the first to share your insights about this piece.

How does it work?

Add your insights

Comments

There are no comments for this story

Be the first to respond and start the conversation.

Sign in to comment

    Find us on social media

    Miscellaneous links

    • Explore
    • Contact
    • Privacy Policy
    • Terms of Use
    • Support

    © 2024 Creatd, Inc. All Rights Reserved.