

It is a programming methodology that uses Objects to build a system or web applications using programming languages like C#, Vb.net, etc. OOP stands for Object Oriented Programming. Stay tuned for more interesting articles.Let me introduce you to OOPS Concepts in C#. I hope you will gain some knowledge about the concepts of OOP from this article. So in this article, I talked about the main concepts of OOP in brief with real-world examples.

So here we can see the same person has different behaviors in different situations. A real-time example of this is when you are in the university you act as an undergraduate when you are in a shop you act like a customer, when you are at home you act like a child. This polymorphism has two types as Runtime polymorphism and Compile Time Polymorphism. So what basically polymorphism does is change that sound method.įor example, the Dog class will have the same method sound inherited from the Animal class and will output ‘Dog can Bark’. Let’s assume there is a subclass that inherits from the Animal class as Dog. It has a method call sound which outputs ‘Animal can make a sound’. For example, let’s take Animal class which is the superclass. So in polymorphism, it uses those methods to perform tasks in different ways. From inheritance it allows us to inherit attributes and methods from another class. The last one is polymorphism which we can explain as “many forms”. Another example is Dog inherits from the Animal superclass. A real-world example of this concept is when a child is born he or she inherits the features of parents such as beauty from mother and intelligence from father. There are several types of inheritance as Single Inheritance, Multiple Inheritance, Hierarchical Inheritance, Multilevel Inheritance, and Hybrid Inheritance. Inheritance comes from the fact that the subclass contains the attributes and methods of the parent class. OOP often organizes classes in a hierarchy to avoid duplication and reduce redundancy.
#OOPS CONCEPTS CODE#
This inheritance provides code reusability and this is used to achieve runtime polymorphism. When one object acquires all or some of a parent object's properties and behaviors, it is known as inheritance. It is a very complex system in which internally many components are functioning together to turn the car in the right direction.

A real-world example for encapsulation is a capsule in which all medicine is encapsulated inside a capsule.Īnother example is the power steering of a car. In Java class is an example of this encapsulation. So what this encapsulation does is that it keeps the data and code safe from external interference. EncapsulationĮncapsulation means binding or wrapping code and data together into a single unit. But we do not know how the input data is sent and how it is verified from the server-side. Then when we press enter we can log into our account. A real-world example of this is when we ride a bike we only concern about things like accelerating, braking but we do not know how it happens.Īnother example is that when we log into Facebook we enter our email and password. In other words, we can say that represents essential features without including the background details.

Simply this means showing only relevant data while hiding unnecessary details of objects. The rest of the article is organized as follows:įirst I will talk about Data Abstraction. So in this article, I am going to talk about these concepts with real-world examples. OOP also has some important concepts such as Data Abstraction, Encapsulation, Inheritance, and Polymorphism. Just like that classes can be used to create many objects.Īnother example is that if we consider fruits as a class, then Apple, Mango, and Banana can be considered as objects. Using this plan we can build as many as houses we want. For example, when we build a house first we create a plan. An object is an instance of a class and it has state and behavior. Class is like a blueprint that can be used to create objects. When it comes to OOP Classes and Objects are the main aspects of it. Actually, what is this object-oriented programming means? Simply OOP is a paradigm that creates objects which contain both data and methods. OOP stands for Object-Oriented Programming.
