This article introduces Object Oriented Programming (OOP) in C#. OOPs is a concept of modern programming language that allows programmers to organize entities and objects. Four key concepts of OOPs are abstraction, encapsulation, inheritance, and polymorphism. Here learn how to implement OOP concepts in C# and .NET.
OOP Features
Here are the key features of OOP:
- Object Oriented Programming (OOP) is a programming model where programs are organized around objects and data rather than action and logic.
- OOP allows decomposing a problem into many entities called objects and then building data and functions around these objects.
- A class is the core of any modern object-oriented programming language such as C#.
- In OOP languages, creating a class for representing data is mandatory.
- A class is a blueprint of an object that contains variables for storing data and functions to perform operations on the data.
- A class will not occupy any memory space; hence, it is only a logical representation of data.
To create a class, you use the keyword "class" followed by the class name:
class Employee
{
}
Object
- The software is divided into several small units called objects. The data and functions are built around these objects.
- An object's data can be accessed only by the functions associated with that object.
- The functions of one object can access the functions of another object.
Objects are the basic run-time entities of an object-oriented system. They may represent a person, a place, or any item the program must handle.
- "An object is a software bundle of related variables and methods."
- "An object is an instance of a class."

A class will not occupy any memory space. Hence to work with the data represented by the class, you must create a variable for the class, which is called an object.
- When an object is created using the new operator, memory is allocated for the class in a heap, the object is called an instance, and its starting address will be stored in the object in stack memory.
- When an object is created without the new operator, memory will not be allocated in a heap; in other words, an instance will not be created, and the object in the stack will contain the value null.
- When an object contains null, it is impossible to access the class members using that object.
class Employee
{
}
Syntax to create an object of class Employee:
Employee objEmp = new Employee();
OOPs Concepts
The key concepts of OOPs are
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
Abstraction
Abstraction is "To represent the essential feature without representing the background details."
- Abstraction lets you focus on what the object does instead of how it does it.
- Abstraction provides a generalized view of your classes or objects by providing relevant information.
- Abstraction is the process of hiding the working style of an object and showing the information about an object understandably.
Real-world Example of Abstraction
Suppose you have an object Mobile Phone.
Suppose you have three mobile phones as in the following:
- Nokia 1400 (Features: Calling, SMS)
- Nokia 2700 (Features: Calling, SMS, FM Radio, MP3, Camera)
- BlackBerry (Features: Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)
Abstract information (necessary and common information) for the "Mobile Phone" object is that it calls any number and can send an SMS.
So, for a mobile phone object, you will have the abstract class as in the following,
abstract class MobilePhone {
public void Calling();
public void SendSMS();
}
public class Nokia1400: MobilePhone {}
public class Nokia2700: MobilePhone {
public void FMRadio();
public void MP3();
public void Camera();
}
public class BlackBerry: MobilePhone {
public void FMRadio();
public void MP3();
public void Camera();
public void Recording();
public void ReadAndSendEmails();
}
Abstraction means putting all the necessary variables and methods in a class.
Example
If somebody in your college tells you to fill in an application form, you will provide your details, like name, address, date of birth, which semester, the percentage you have, etcetera.
If some doctor gives you an application, you will provide the details, like name, address, date of birth, blood group, height, and weight.
See in the preceding example what is in common?
Age, name, and address, so you can create a class that consists of the common data. That is called an abstract class.
That class is not complete, and other classes can inherit it.
Here is a detailed article on Abstraction In C#.
Encapsulation
Wrapping up a data member and a method together into a single unit (in other words, class) is called Encapsulation. Encapsulation is like enclosing in a capsule. That is, enclosing the related operations and data related to an object into that object.
Encapsulation is like your bag in which you can keep your pen, book, etcetera. It means this is the property of encapsulating members and functions.
class Bag {
book;
pen;
ReadBook();
}
- Encapsulation means hiding the internal details of an object, in other words, how an object does something.
- Encapsulation prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.
- Encapsulation is a technique used to protect the information in an object from another object.
- Hide the data for security, such as making the variables private, and expose the property to access the private data that will be public.
So, when you access the property, you can validate the data and set it.
Example 1
class Demo {
private int _mark;
public int Mark {
get {
return _mark;
}
set {
if (_mark > 0) _mark = value;
else _mark = 0;
}
}
}
Real-world Example of Encapsulation
Let's use as an example Mobile Phones and Mobile Phone Manufacturers.
Suppose you are a Mobile Phone Manufacturer and have designed and developed a Mobile Phone design (a class). Now by using machinery, you are manufacturing Mobile Phones (objects) for selling; when you sell your Mobile Phone, the user only learns how to use the Mobile Phone but not how the Mobile Phone works.
This means that you are creating the class with functions and by with objects (capsules), of which you are making available the functionality of your class by that object and without interference in the original class.
Example 2
TV operation
It is encapsulated with a cover, and we can operate it with a remote, and there is no need to open the TV to change the channel. Everything is private except the remote, so anyone can access the remote to operate and change the things on the TV.
Here is a detailed article on Encapsulation In C#.
Inheritance
When a class includes a property of another class, it is known as inheritance. Inheritance is a process of object reusability.
For example, a child includes the properties of its parents.
public class ParentClass {
public ParentClass() {
Console.WriteLine("Parent Constructor.");
}
public void print() {
Console.WriteLine("I'm a Parent Class.");
}
}
public class ChildClass: ParentClass {
public ChildClass() {
Console.WriteLine("Child Constructor.");
}
public static void Main() {
ChildClass child = new ChildClass();
child.print();
}
}
Output
Parent Constructor.
Child Constructor.
I'm a Parent Class.
Here is a detailed article on Types Of Inheritance In C#.
Polymorphism
Polymorphism means one name, many forms. One function behaves in different forms. In other words, "Many forms of a single object is called Polymorphism."
Real-world Example of Polymorphism
Example 1
A teacher behaves with his students.
A teacher behaves with their seniors.
Here the teacher is an object, but the attitude is different in different situations.
Example 2
A person behaves like a son in a house at the same time that the person behaves like an employee in an office.
Example 3
Your mobile phone, one name but many forms:
- As phone
- As camera
- As mp3 player
- As radio
Here is a detailed article on Polymorphism in .NET.
Differences between Abstraction and Encapsulation
| Abstraction | Encapsulation |
| 1. Abstraction solves the problem at the design level. | 1. Encapsulation solves the problem at the implementation level. |
| 2. Abstraction hides unwanted data and provides relevant data. | 2. Encapsulation means hiding the code and data in a single unit to protect the data from the outside world. |
| 3. Abstraction lets you focus on what the object does instead of how it does it | 3. Encapsulation means hiding the internal details or mechanics of how an object does something. |
| 4. Abstraction: Outer layout, used in terms of design. For example: An external Mobile Phone like it has a display screen and keypad buttons to dial a number. |
4. Encapsulation- Inner layout, used in terms of implementation. For example, the internal details of a Mobile Phone and how the keypad button and display screen are connected using circuits. |
The easier way to understand abstraction and encapsulation is as follows.
Real-world Example
Use an example of a Mobile Phone
You have a Mobile Phone; you can dial a number using keypad buttons. You don't even know how these are working internally. This is called abstraction. You only have the information that is necessary to dial a number. But the not internal working of the mobile. But how does the Mobile Phone work internally? How are the keypad buttons connected to the internal circuit? That is called Encapsulation.
Summary
This article taught you the basics of OOPs and implementing OOPs in C# and .NET.
Continue readings
Here is a list of some free books on C#:

Stephen JamesPosted Oct 23, 2025, 6:15 PM
These is very enriching and mind blowing
Robert ButlerPosted Oct 29, 2024, 6:41 PM
The examples here really need work. Same with the inheritance page this page links to. Mis-spellings, unconventional naming, and just not very intuitive examples.
IMAD AYOUBPosted Feb 19, 2023, 10:32 PM
Nice explanation. Thanks a lot.
Naveed ZamanPosted Feb 5, 2022, 2:24 PM
Please correct this sentence "class is a blueprint of an object" correct sentence is object is a blueprint of a class.
Nivya KarthikPosted Aug 6, 2021, 3:51 AM
Suppose If we have to ignore one of the pillar from these 4 pillars which one we can exclude? Why ?And how we can achieve that using other pillars?
Sharad RastogiPosted Jun 7, 2021, 12:27 PM
Its very easy to understand..
Bhanu TPosted Apr 25, 2021, 3:35 PM
Thank you soo much
Sai KPosted Mar 21, 2021, 6:50 AM
Thanks, Manish!! very well explained
divya swamiPosted Mar 19, 2021, 12:40 PM
Nice Explanation
ahmadjon jorayevPosted Feb 19, 2021, 11:39 AM
It is very useful
Amit Kumar SinghPosted Sep 1, 2020, 3:04 AM
Nice article .. Thanks for sharing !!
Rob FletcherPosted Jul 28, 2020, 8:48 AM
You should update your phone example. Nokia and Blackberry? Some would say, "what are those," now.
Dinesh GabhanePosted Nov 7, 2019, 8:26 AM
Very Nice Article
Rupesh VermaPosted Sep 30, 2019, 1:10 AM
Very nice article. i have learn a lot from it
Amit AgarwalPosted Aug 24, 2019, 2:50 AM
Nice explanation.....
Rohit GhoshPosted Jun 26, 2019, 9:17 PM
Very nice article for me and for a beginner
Reshma BhalekarPosted Mar 11, 2019, 4:31 AM
Very nice article and real-life examples... Keep it up..
Udit GandhiPosted Jan 10, 2019, 4:19 AM
I believe you are confused about abstraction and encapsulation, you have mixed the concepts. You need to verify before submitting articles like this.
Bhavesh JadavPosted Aug 18, 2018, 1:42 AM
Super explanation sir.....
Patel SoniyaPosted May 28, 2018, 4:09 AM
Great Explanation...........
Amol KumbhkarnaPosted Apr 13, 2018, 6:17 AM
Great article .. Keep It Up...
Laxmidhar SahooPosted Dec 2, 2017, 6:28 AM
This will helpfull to my blog C# Class
Mayur PadhiyarPosted Jun 30, 2017, 8:58 PM
The article is very good but I also want to know about Polymorphism but the link you have provided is not a link it is a text "Polymorphism in .Net" link is not set. Please give us a link. Thank you.
Divya MadavanPosted Jun 23, 2017, 7:09 AM
Really a great artical easily understandable. .
Vaibhav PatilPosted Jun 13, 2017, 12:19 PM
Nicely and simply explained. Recommend for beginners.
prabhakar srivastavaPosted Jun 13, 2017, 8:31 AM
Great Post Manish Cheers!
Nilankar GhoshPosted May 19, 2017, 1:23 AM
Could you plz send me PDF version of this eBook.I could not download it.plz also mention other good oops ebooks. Thanks.......... Nilankar. [email protected]
divya shashaPosted Mar 20, 2017, 5:16 AM
Sir,Nice explanation.Can you please tell me in one line. why we use oops in programming language.
Twana IsmaelPosted Jan 30, 2017, 3:15 AM
The article was very good but i couldn't download the ebooks ..
Tejaswi KhandarePosted Jan 14, 2017, 4:21 AM
Hello sir, you gave very good explanation, but the example of abstraction you gave, is of the abstract class. I think, Abstract class and abstractions are different things. Then, how you achieve abstraction?
Joe WilsonPosted Jan 6, 2017, 7:33 AM
Thank you very much for sharing.
sumit yadavPosted Dec 15, 2016, 7:50 AM
Sir nice example but the first one you show how to make an object of a class, the syntax i am saying...
SubashPosted Nov 16, 2016, 8:17 PM
Hello sir very good explanation and simple example makes reader to clear i looking your feature articles too have a great day
Yogeshwar GoswamiPosted Oct 31, 2016, 2:43 PM
Nice
rehan khanPosted Sep 8, 2016, 4:36 PM
U r just Awesome...! :)
Ramesh PalaniappanPosted Aug 18, 2016, 8:19 AM
Nice
kalu singh raoPosted Jul 7, 2016, 8:40 AM
Nice...
praveen kumarPosted Jun 16, 2016, 8:19 AM
thank you
sachith wickramaarachchiPosted Jun 13, 2016, 2:36 PM
Nice Post.
vishal reddy k vPosted May 28, 2016, 11:05 AM
very nice explanation manish, but just one thing is instead of writing the function public void Calling(); if u write public void Calling(){} its much clear explanation for learners as they try to copy and excute .. its just my view ... but very nicely explained everything
DibakarPosted May 18, 2016, 4:55 AM
Nice Post. Abstraction is too good.
sachith wickramaarachchiPosted May 10, 2016, 2:00 PM
Good post
monil thakorPosted Mar 11, 2016, 6:24 AM
Accha he...
Pawan TiwariPosted Jan 27, 2016, 5:15 AM
Abstraction example is outstanding....
Phaneendra ChakravaramPosted Jan 23, 2016, 10:00 AM
tq
Uday Bhan SinghPosted Oct 21, 2015, 5:45 AM
once again thanks Manish Agrahari ji
joe rozarioPosted Oct 18, 2015, 1:57 AM
nice one. please make Polymorphism better.
Santosh MPosted Oct 12, 2015, 7:58 AM
nice explanation
Nihal AhmedPosted Sep 30, 2015, 7:41 AM
nice one
santosh yadavPosted Aug 19, 2015, 4:20 PM
nice
Amit HabuPosted Aug 13, 2015, 10:59 PM
Thanks for explaining in simple and real world examples, very nice.
Manasi JarandePosted Jul 8, 2015, 12:20 AM
short and sweet
balaji jayamangalaPosted Jul 6, 2015, 7:59 AM
super
balaji jayamangalaPosted Jul 6, 2015, 7:59 AM
super
Rajendra TaradalePosted Jul 2, 2015, 5:30 AM
good explained
Kalai SelvanPosted Jun 17, 2015, 12:45 AM
Good explanation!!!
vishal boradePosted May 27, 2015, 6:10 AM
nice one
Gowtham RajamanickamPosted May 20, 2015, 1:17 AM
easy to learn
Gowtham RajamanickamPosted May 20, 2015, 1:17 AM
nice presentation
Upendra Pratap ShahiPosted May 11, 2015, 3:06 AM
nice..
kazi salimullahPosted May 6, 2015, 6:31 AM
Very nice presentation of basic OOP shortly,thanks.
Rohidas KadamPosted Mar 14, 2015, 7:11 AM
Thanks for useful information
Web DeveloperPosted Dec 23, 2014, 12:09 PM
Please explain is it so? "Hide the data for security such as making the variables private, and expose the property to access the private data that will be public." it looks like Abstraction. This way we are creating Abstraction.
Web DeveloperPosted Dec 23, 2014, 12:07 PM
Great explanation. thanks.
Priyank PandyaPosted Oct 10, 2014, 1:29 AM
its nice to understand
Naitik JaniPosted Oct 9, 2014, 4:30 AM
Good Explaination..
Pooja SharmaPosted Sep 20, 2014, 2:32 AM
Nice one
Dharmendra kuma yadavPosted Aug 27, 2014, 2:09 PM
easy to understand and explain also easy
Mayur NabedaPosted Jul 30, 2014, 4:11 PM
Good One, Can you go for interface also ??
Satheesh Kumar PilliPosted Jul 1, 2014, 8:47 AM
Good article with real time examples
Ganapathi GPosted Jun 27, 2014, 2:05 PM
Good comparison to understand easily.
Sonu RajPosted May 31, 2014, 11:34 PM
very Nice article about the difference between abstraction and Encapsulation
Muhammad JawwadPosted May 21, 2014, 4:29 PM
NICE (Y)
naveen dusaPosted Apr 6, 2014, 3:54 AM
Very good explanation for beginners thanks.. :)
Surya PrakashPosted Mar 26, 2014, 3:45 AM
good and neat explanation , it's easy to understand
prashant bhajantriPosted Mar 25, 2014, 6:56 AM
good explanation with real time examples :)
piyush rajPosted Feb 28, 2014, 12:42 AM
awesomes explaination
kanna kannaPosted Dec 30, 2013, 12:16 AM
Very Nice Article
hari krishnanPosted Nov 25, 2013, 1:17 AM
Nice understandable Article...Thanks!!!!!!
Hitesh chotaliyaPosted Oct 1, 2013, 7:12 AM
Very Nice and Good Understanding Article
Mahesh AllePosted Sep 30, 2013, 10:31 AM
Simple, very clear to understand. Good Job.
Rohatash KumarPosted Sep 30, 2013, 8:40 AM
Good Article.
Lax LaxPosted Sep 30, 2013, 7:13 AM
Thank you for this great article. It made things much clear for me.
Manish AgrahariPosted Jun 3, 2013, 10:42 AM
@Mahesh Chand Sir:- Thank You sir... I am pleased to have your comment on my post..
Manish AgrahariPosted Jun 3, 2013, 10:41 AM
Thanks a lot Dinesh Beniwal, Kundan Kumar and Isman Subarkah..
Isman SubarkahPosted May 31, 2013, 12:44 PM
great article, after read this article, i feel that i have better understanding about object oriented programming.
Mahesh ChandPosted May 29, 2013, 8:43 AM
I love your "Life Funda" posted on your profile. Very nice!
Kundan KumarPosted May 29, 2013, 7:58 AM
Very nice article.
Dinesh BeniwalPosted May 29, 2013, 7:52 AM
Good Start Manish, Welcome to the C# Corner.