+ 4
Can anyone help me to understand the concept of OOP in c++?
Like by using OOP concept how can we implement the real wolrld happenings in a program.....
1 Réponse
+ 3
OOP has 4 pillars: Abstraction, Encapsulation, Inheritance, and Polymorphism.
1. Abstraction is only showing to the user what they need to know, and keeping the background work within the class. It is hiding the implementation, and showing only the functionality.
For example, after I type into this comment box, I don't need to know where and how this text is processed behind the scenes. All I need to see is that the comment is sent and that you can see it.
2. Encapsulation is the binding of data members and methods into a unit. Encapsulation leads to data hiding, which prevents the data itself from being misused. The use of access modifiers is a way of encapsulation.
A real world example would be those medicine capsules. That's why it's called encapsulation, it keeps the actual medicine in a capsule to prevent it from being misused.
3. Inheritance is simply when an object is based on their parent object using the same implementation.
A great example would be a general animal and a specific species. We can say that there is a fish, which is the base, or the parent class. The different species of fish such as goldfish, lionfish, milkfish, etc. are the species based on fish. They are all fish, so they inherit the general characteristics of a fish, such as gills and a tail.
4. Finally, Polymorphism is the ability for an object to take on many forms.
Take the fish again as an example, I didn't mention that the different species of fish also have different characteristics, such as a goldfish being gold for example. A fish is still a fish, but a fish can take on multiple forms, such as the many species of fish out there.