Introduction
We are going to see here some real life examples of Object Oriented Programming (OOPS).
The following are the principles of OOPS:
- Class
- Object
- Constructor (Note: This is not actual principal)
- Abstraction
- Encapsulation
- Polymorphism
- Inheritance
- Destructor (Note: This is not actual principal)
Description
Before proceeding further let’s look into background.Before OOPS concept came into picture (market) there was "C Language" designed & developed by Dennis Ritchie in 1972 at AT & T Laboratory.
C language is a general purpose, block structured, case sensitive & procedure oriented language.
Program execution always goes from top to bottom.
Let’s see how a C program gets compiled & run.
CLR like the following figure:
Example
This example is divided into two parts; firstly, Procedure Oriented approach and secondly Object oriented approach.
There is one poor family in Maharashtra. They have their own business to pick up fish from sea & sell that in the local market. In that family there were members including husband, wife & children. Everyday they do the same thing for their business. After some years they did not earned a good amount of profit from their business because daily expenses were bigger than what they earned from the business.
So husband & wife decided to do some other business. So they visited on of their relatives and ask for some suggestions. They got a suggestion to make Ganesh statues to sell them. This was suggested because it is one of the best business since Ganesh Chaturthi is an important festival and celebrated across Indian homes.
They follow the procedural approach like C program approach:
- They take Shaadu (Fire Clay / dry mud powder), water, knot, color, brush, etc.
- First they take Shaadu in a vessel and start mixing water. Keep in mind the mixture can get very thick making your fingers ache as you try to take off the clay sticking on them.

- After this mixture is ready, give them a shape of Ganesh statue.

- Start off with creating a base structure of the idol / Ganesh statue:

- Leave the idol / statue to dry naturally for 2 days at least, after 2 days if statue is completely dry then start giving color to them.
For doing the above procedure they need extra time & days because firstly they have to give it a proper shape, statue should need to dry completely, after that give proper color to this statue. If sometimes statue gets cracked or shape didn't came out well, then they have do repeat the whole procedure from first to last. So it is very time consuming.
In this procedure suppose for completing 1 Ganesh statue it takes 5 days i.e approximately each month they completed 6 Ganesh statue (every year 72).
For first year they sold 72 statues. After this 72 statue reached in 72 homes, relatives & neighbours loved the statue. So for next year this family got an advance order of 2000 Ganesh statue which are in different shapes like 1 feet, 2 feet, 5 feet, 10 feet & 20 feet.
The family member again visited their relative to resolve these relevant questions i.e How can they complete 2000 Ganesh statues in one year? So they gave suggestion to use mold (meaning - a hollow container used to give shape to molten or hot liquid material when it cools and hardens) to give proper shapes to Ganesh statues.
Now the family used these different molds like 1 feet, 2 feet, 5 feet, 10 feet & 20 feet. Following this, they can complete 100 Ganesh statue per day.
Here they followed the procedure which is Object Oriented Programming Approach.
- Firstly, they took Shaadu in a vessel and started mixing water, after they took knot, mixed it in that pot & added this knot to mold.

This mold is like a predefined class.
Class
- Class is a blue print of newly created things.
- Class contains characteristics (class members) and behaviors (function applied on these characteristics).
- It is a blue print such as if we bought a land / space & would like to build a beautiful house on that land then we first draw a sketch.
- In our programming language before going to create any application first we decide which classes we are going to create.
- class Ganesh_Statue {
- // class members declerations
- public string shaadu;
- public string knot;
- public string water, pot;
- public string One_Tusk, Big_Head;
- public string chain, ring;
- public string mouse_color, Eye_Color, Skin_Color;
- public void Do_Painting() {}
- }
Object
- Objects are instances of class.
- Whenever they create first Ganesh statue from this mold, it creates first object & it will look like the following:

- Whenever they create multiple Ganesh statues (multiple objects) by using mold and added other parts like hand, legs etc, it looks like the following:
Abstraction
- Abstraction means hiding the implementation details.
- This family only knows which type of material they have used to create a statue.
- This family uses knot, shaadu, water, etc to make the statue and this information is hidden from the users (who can buy this Ganesh statues).
If we ask anybody that what we can understand from the above image, then he / she will say that these are all stones.
Constructor
- Constructor is a method that is called when instance of an object is created.
- They have the same name as a class.
- In our example default constructor is to be set with values such as eye color, skin color and mouse color.
- After calling the default constructor Ganesh statue will look like the following:

A. Parameterized Constructor- //constructor
- public Ganesh_Statue() {
- Console.WriteLine("**** Dafult Constructor in base class starts from here ****");
- Eye_Color = "Black";
- Skin_Color = "Redish_White";
- mouse_color = "Black";
- Console.WriteLine("Default values of Eye color: " + Eye_Color);
- Console.WriteLine("Default values of skin color: " + Skin_Color);
- Console.WriteLine("Default values of mouse colo: " + mouse_color);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- A constructor with at least one parameter is called parameterized constructor.
- In our example suppose a wealthy businessman came to this family & gave some parameter like he wants to add his own jewellery to statue like chain & ring.
- // parameterized constructor
- public Ganesh_Statue(string x, string y) {
- chain = x;
- ring = y;
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine("**** Parameterized Constructor of base class starts from here ****");
- Console.WriteLine("chain color: " + x + " ring color: " + y);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
Encapsulation
- Encapsulation means biding data & function together.
- For example, we visit the Doctor or Medical store and take medicine(capsule / tablet), then the plastic cover is used to bind with inner powder which helps us to recover.
Polymorphism
Now this family has to decide about some people who have domain specific knowledge like painting.
- Polymorphism is the way in which we can define a multiple function in a single name. i.e single name & multiple meaning.
- Polymorphism means assigning a single name but there can be multiple behaviors. Means name of the function is same but its definitions are different.
- Polymorphism means single name & multiple meaning & whenever we try to access that particular name there must be a binding between that call & between that function, so there are two types of binding to call that function.
- Compile time binding.
- Run time binding
1. Compile Time Polymorphism
In case of this Polymorphism, function call & its definition bind at compile time.
There are two ways to achieve this Polymorphism.A. Function Overloading
In this example they (that family) hire some painter who knows only painting. If this family provides different types of statues to this painter then he has to do the work. In this way we can achieve overloading.

- // function overloading without parameter
- public void Do_Painting() {
- Console.WriteLine("**** You are in Function Overloading Without Parameter ****");
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- Passing different parameters like we would like to do some painting of statue of shivaji, different solders of forts in Diwali & Durga statue etc.
- // function overloading with parameter
- public void Do_Painting(string Statue_Name) {
- Console.WriteLine("**** You are in Function Overloading With Parameter ****");
- Console.WriteLine("Statue Name is: " + Statue_Name);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }

B. Operator Overloading
In this example first brush is used to give a color and after finishing color of whole statue, this brush gets cleaned by using water & used for removing shadu from small surface area like between finger, below eye, between legs, corner of legs / hands, etc.
In this case brush is used as an operator.
Now output of our program is (refer code for more info)- public static void operator brush(string paint)
- {
- // give color to statue using brush
- }
- public static void operator brush(string paint)
- {
- // remove shadu from small surface area like between finger, below of eye, between legs, corner of legs / hands
- }
Inheritance
Now suppose the wealthy person comes at this family’s house. He shows some photos of Lalbag Raja (Mumbai) to this family & now he need the same Ganesh statue like the following:

So as shown in the above image this family decides to add mold with seat on a gold-plated stool decked with ornaments (i.e. gold sofa).
In this situation, if we see our class is already ready i.e. base class from which we created Ganesh statues, we need to add a new functionality i.e Inheritance.
When people buy the Ganesh statue, they keep it at their home. Puja should begin with invocation of Lord Ganesha, one should chant Mantra in front of the Murti, by showing Avahan Mudra (Avahan Mudra is formed by joining both palms and folding both thumbs inwards).
After Lord Ganesha has been invoked and got installed, take five flowers in Anjali (by joining palm of both hands).
Program
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Real_Life_Example_OOPS {
- class Ganesh_Statue {
- // class members declerations
- public string shaadu;
- public string knot;
- public string water, pot;
- public string One_Tusk, Big_Head;
- public string chain, ring;
- public string mouse_color, Eye_Color, Skin_Color;
- //constructor
- public Ganesh_Statue() {
- Console.WriteLine();
- Console.WriteLine("**** Dafult Constructor in base class starts from here ****");
- Eye_Color = "Black";
- Skin_Color = "Redish_White";
- mouse_color = "Black";
- Console.WriteLine("Default values of Eye color: " + Eye_Color);
- Console.WriteLine("Default values of skin color: " + Skin_Color);
- Console.WriteLine("Default values of mouse colo: " + mouse_color);
- Console.WriteLine();
- }
- // parameterized constructor
- public Ganesh_Statue(string x, string y) {
- chain = x;
- ring = y;
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine("**** Parameterized Constructor of base class starts from here ****");
- Console.WriteLine("chain color: " + x + " ring color: " + y);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- // function overloading without parameter
- public void Do_Painting() {
- Console.WriteLine("**** You are in Function Overloading Without Parameter ****");
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- // function overloading with parameter
- public void Do_Painting(string Statue_Name) {
- Console.WriteLine("**** You are in Function Overloading With 1 Parameter ****");
- Console.WriteLine("Statue Name is: " + Statue_Name);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- // operator overloading
- //public static void operator brush(string paint)
- //{
- // // give color to statue
- //}
- // public static void operator brush(string paint)
- //{
- // // remove shadu from small surface area like between finger, below of eye, between legs, corner of legs / hands
- //}
- public void Do_Painting(string Statue_Name, string statue_2) {
- Console.WriteLine("**** You are in Function Overloading With 2 Parameter ****");
- Console.WriteLine("Statue 1st is: " + Statue_Name + "Statue 2nd is: " + statue_2);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- }
- class Derived: Ganesh_Statue {
- public string sofa_color;
- void add_functionality() {
- sofa_color = "blue";
- Console.WriteLine("**** Here we are going to achieve Inheritance ****");
- Console.WriteLine("Eye color: " + Eye_Color + " skin color: " + Skin_Color);
- Console.WriteLine("Added sofa color: " + sofa_color);
- Console.WriteLine("____________________________________________________________________________");
- Console.WriteLine();
- }
- static void Main(string[] arg) {
- Ganesh_Statue obj1 = new Ganesh_Statue();
- Ganesh_Statue obj = new Ganesh_Statue("silver", "diamond");
- obj.Do_Painting();
- obj.Do_Painting("soldiers in diwali festival");
- obj.Do_Painting("animal", "shivaji statue");
- Derived obj2 = new Derived();
- obj2.add_functionality();
- Console.ReadKey();
- }
- }
- }
Destructor
Now conclude Shri Ganesha Puja with Visarjan after 7 days or 10 days. This is called Destructor of an object.

Summary
This article will help freshers as well as experienced candidates to crack the technical interview rounds. In many interviews interviewers ask about real life OOPS example.
Hope you enjoyed this complete article on Real Life Examples. Don’t forget to comment on the article.

mathi mPosted Feb 19, 2022, 2:20 PM
Thank you , oops concept simply cleared
Mr. SabihPosted Sep 24, 2021, 9:22 AM
Explanation couldn't be more perfect than this one.
srujanasri PotharajulaPosted Aug 11, 2021, 7:21 AM
Excellent explanation
Sanjay KumarPosted Aug 2, 2021, 12:51 PM
Nice article & very usefull
Saurabh VasaniPosted Apr 16, 2018, 2:45 AM
Thanks and really appriciable....Keep it up bro....
Shubham JainPosted Jan 12, 2018, 6:43 PM
Perfect way to explain :)
chinnuPosted Nov 16, 2016, 7:03 AM
Nice one and thank you for your time.
Bhuvanesh MohankumarPosted May 10, 2016, 2:27 AM
Good one..
Sonu ChaudharyPosted Mar 16, 2016, 3:23 AM
great
Rupesh KahanePosted Feb 5, 2016, 2:05 PM
thanks to Akanksha Ladsawangikar & amit singh also
Amit Kumar SinghPosted Feb 3, 2016, 4:46 AM
Nice Article
Akanksha LadsawangikarPosted Jan 9, 2016, 3:50 AM
Nice example indeed! Would help to brush up OOPS concepts. :-)
Rupesh KahanePosted Dec 23, 2015, 8:18 PM
Thanks sreenivasa reddy ganta
sreenivasa reddy gantaPosted Dec 22, 2015, 8:58 PM
great job & great explanation ....thanks
Rupesh KahanePosted Nov 27, 2015, 5:40 AM
thanks Jaipal Reddy
Jaipal ReddyPosted Nov 27, 2015, 3:54 AM
Great work.
Rupesh KahanePosted Nov 17, 2015, 11:28 AM
Umamaheswara Rao Dasari thanks
Umamaheswara Rao DasariPosted Nov 17, 2015, 8:52 AM
wow
Rupesh KahanePosted Nov 4, 2015, 7:36 AM
Rupesh Sayankar thanks for your great words
Rupesh SayankarPosted Nov 4, 2015, 5:56 AM
Really Very Nice Article... permanant OOPs print in your brain...
Rupesh KahanePosted Oct 25, 2015, 1:38 PM
Thanks Santhakumar Munuswamy sir
Santhakumar MunuswamyPosted Oct 25, 2015, 11:56 AM
Good one
Rupesh KahanePosted Oct 19, 2015, 1:55 PM
Priyaranjan K S thanks a lot
Rupesh KahanePosted Oct 19, 2015, 1:55 PM
Gowtham K thanks
Priyaranjan K SPosted Oct 19, 2015, 12:42 PM
Good One
Gowtham KPosted Oct 19, 2015, 12:31 PM
Good job
Rupesh KahanePosted Oct 19, 2015, 9:43 AM
Thx mukesh, humayun, sanjay, rajan and sibeesh sir
Sibeesh VenuPosted Oct 19, 2015, 8:54 AM
Nice Share
Rajan AroraPosted Oct 19, 2015, 7:49 AM
Superb
Sanjay SabariyaPosted Oct 19, 2015, 7:05 AM
Excellent.
Humayun Kabir MamunPosted Oct 19, 2015, 6:50 AM
Nice...
Mukesh KumarPosted Oct 19, 2015, 5:13 AM
Good Job
Rupesh KahanePosted Oct 19, 2015, 4:51 AM
Thx kamlesh
Kamlesh BhorPosted Oct 19, 2015, 4:33 AM
Nice.. Thanks for sharing...
Rupesh KahanePosted Oct 19, 2015, 3:56 AM
Thanks sujeet sir
Sujeet SumanPosted Oct 19, 2015, 3:40 AM
Nice one......................
Rupesh KahanePosted Oct 19, 2015, 3:37 AM
Thx nilesh sir
Nilesh JadavPosted Oct 19, 2015, 3:03 AM
Good Share
Rupesh KahanePosted Oct 19, 2015, 2:13 AM
Thx harshad
Rupesh KahanePosted Oct 19, 2015, 2:13 AM
Thx vinodh
Vinodh NarayananPosted Oct 19, 2015, 2:04 AM
good one
Harshad PansuriyaPosted Oct 19, 2015, 1:57 AM
Nice one