---
title: "OOP (Object Oriented Programming)"  
description: "OOPs is a problem solvingmethodology. It decomposelarger program into smaller unit called classes. It is easy to use, modify  Object orientation- Focu"  
author: "Royce Roy"  
published: 2017-01-21  
updated: 2018-03-17  
canonical: https://www.mindstick.com/blog/11278/oop-object-oriented-programming  
category: "oops"  
tags: ["oops"]  
reading_time: 3 minutes  

---

# OOP (Object Oriented Programming)

OOPs is a problem solving methodology. It decompose larger program into smaller unit called classes. It is easy to use, modify\

**Object [orientation](https://www.mindstick.com/interview/2604/what-is-orientation)-** Focus will be an object rather than whole system.

Class- it is like a blueprint or template for its object. It wrap member function and data into single unit.it is the logical representation of some real world entity or object.

Object-It is an instance of the class/physical representation of the logic class. We can access the member of the class by its object

```
using System;            using
System.Collections.Generic;using System.Linq;using System.Text;using
System.Threading.Tasks; namespace ConsoleApplication6{    class employee    {        public int empno;        public string empname;    }        class Program    {         static void Main(string[] args)        {            //to create object            employee emp = new employee();            emp.empno = 1001;            emp.empname = "Mindstick";            Console.WriteLine(emp.empno);            Console.WriteLine(emp.empname);            Console.ReadKey();        }    }} 
```

**Pillar of OOP:**

**1 [Encapsulation](https://www.mindstick.com/articles/12229/encapsulation-and-access-specifier)-** it is the feature of [data hiding](https://www.mindstick.com/forum/33865/what-is-data-hiding) with help of [access modifiers](https://www.mindstick.com/articles/338838/explain-access-modifiers-in-java), so that it cannot by accessed by the outside world here outside world means [outside the class](https://www.mindstick.com/interview/2468/can-you-access-the-private-method-from-outside-the-class).

- Access modifiers
- Public-accessible everywhere (in class where defined, [child class](https://www.mindstick.com/forum/159389/how-to-remove-child-class-from-active-div) by object)
- Protected-In class in child class
- Private-only in class
- Default-only in class
- Default-private

**Encapsulation example.**

```
using System;using
System.Collections.Generic;using System.Linq;using System.Text;using
System.Threading.Tasks;                        namespace ConsoleApplication6{    class employee    {        public int empno;        protected string empname;        private int age;    }        class Program    {         static void Main(string[] args)        {            //to create object            employee emp = new employee();            emp.empno = 1001;            emp.empname = "Mindstick";// this line shows error            emp.age = 20;// this line shows error due to protection level            Console.WriteLine(emp.empno);            Console.WriteLine(emp.empname);            Console.ReadKey();        }    }} using System;using
System.Collections.Generic;using System.Linq;using System.Text;using
System.Threading.Tasks; namespace ConsoleApplication6{    class employee    {        public int empno;        protected string empname;        private int age;    }    class salary:employee    {        public void display()        {            empno = 1002;            empname = "Mindstick";            age=10//error        }    }        class Program    {         static void Main(string[] args)        {            //to create object            employee emp = new employee();            emp.empno = 1001;            emp.empname = "Mindstick";// this line shows error            emp.age = 20;// this line shows error due to protection level            Console.WriteLine(emp.empno);            Console.WriteLine(emp.empname);            Console.ReadKey();        }    }} 
```

**For accesing [private member](https://answers.mindstick.com/qa/110885/what-is-the-indian-parliament-private-member-s-bill) ex.**

```
using System;using
System.Collections.Generic;using System.Linq;using System.Text;using
System.Threading.Tasks; namespace ConsoleApplication6{    class employee    {                private int age;                public void setage(int x)                {                    if (x >= 18 && x <= 100)                    {                        age = x;                        Console.Write("age set!");                    }                    else                        Console.WriteLine("age not set");                }    }           class Program    {         static void Main(string[] args)        {            //to create object            employee emp = new employee();            emp.setage(10);               emp.setage(20);            Console.ReadKey();        }    }}
```

\

![OOP (Object Oriented Programming)](https://www.mindstick.com/blogs/1a54c018-9089-4cf5-9440-be2d1faf316c/images/cff8e2eb-34e2-4fd4-8c19-81d584fce34b.png)\

**Inheritance:**

It is the feature of OOP .To inherited the property of one class into another class.

It support single inheritance, multi-level inheritance, hierarchical inheritance

Example to show inheritance

```
  class A                  {                            public int x;       
    }    class B:A //single level    {        int y;    }    class c:B//multilevel    {        int c;    }    class D : A//heirarchical    {    }
```

\

**You can also visit these related articles and blogs**

[Introduction to OOPS (Object oriented Programming System)](https://www.mindstick.com/Articles/1558/introduction-to-oops-object-oriented-programming-system)

[What is a information hiding in object oriented programming](https://www.mindstick.com/Interview/23097/what-is-a-information-hiding-in-object-oriented-programming)

[What is difference between object oriented programming language and object based programming language?](https://www.mindstick.com/interview/22897/what-is-difference-between-object-oriented-programming-language-and-object-based-programming-language)

\

---

Original Source: https://www.mindstick.com/blog/11278/oop-object-oriented-programming

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
