We all have faced this OOPs moment in our life right. That’s OK.
I am going to explain OOPs concept of Java using real time example.
Let’s first try to understand what is OOPs.
What is OOP?
OOP is Object Oriented Programming. According to all our friend Wikipedia, Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs.
OOPS concepts in JAVA are: Abstraction, Polymorphism, Encapsulation and Inheritance.
I am relating OOPs concept to a real time object called Instant Pot.
I know Instant Pot is kitchen friendly, cooking friendly but now we are going to understand OOPs concept of JAVA using Instant Pot.
We generally use an Instant Pot for cooking purposes which include: boiling eggs, preparing rice, cooking lentils etc..
· Instant Pot is an object because it is a real time entity, it has its own state, behaviour, and identity. They are manufactured by various companies and each of the brands have different features.
· Classes in JAVA are logical entities which have methods, fields, constructors, and a lot more. In an Instant Pot, you can consider its specifications as classes, be it dual pressure settings, microprocessor controlled programs, sensors, and other basic features.
Providing necessary information and hiding the unwanted information is Abstraction. The concept of abstraction focuses on what an object (Instant Pot) does, instead of how an object is represented or how it works. So, it is hiding the implementation and showing you the functionality only.
Encapsulation means that we want to hide unnecessary details from user.
After adding all ingredients into Instant Pot and closing lid, we set time, press on slow cook. But the entire process of adding ingredients, closing lid, setting certain features to until it is cooked everything is hidden from us.
Polymorphism means performing process in different ways. In Instant Pot, we can cook rice by pressure cook and also by slow cook. The basic purpose of an Instant Pot is to cook whereas the modes enable you to cook in different ways.
Inheritance means one class(sub/child class) is deriving all properties from other class(parent class). The basic purpose of using an Instant Pot is cooking. There are different brands, so the brands of n Instant Pot are using this basic functionality(cooking) by extending Instant Pot class functionality and adding their own new features to their respective brand.
I hope you all have got some basic understanding of OOP concept of JAVA with Instant Pot.
Thankyou all for your valuable time.