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, 2:15 PM EDT
These is very enriching and mind blowing
Robert ButlerPosted Oct 29, 2024, 2:41 PM EDT
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, 5:32 PM EST
Nice explanation. Thanks a lot.
Naveed ZamanPosted Feb 5, 2022, 9:24 AM EST
Please correct this sentence "class is a blueprint of an object" correct sentence is object is a blueprint of a class.
Nivya KarthikPosted Aug 5, 2021, 11:51 PM EDT
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, 8:27 AM EDT
Its very easy to understand..
Bhanu TPosted Apr 25, 2021, 11:35 AM EDT
Thank you soo much
Sai KPosted Mar 21, 2021, 2:50 AM EDT
Thanks, Manish!! very well explained
divya swamiPosted Mar 19, 2021, 8:40 AM EDT
Nice Explanation
ahmadjon jorayevPosted Feb 19, 2021, 6:39 AM EST
It is very useful
Amit Kumar SinghPosted Aug 31, 2020, 11:04 PM EDT
Nice article .. Thanks for sharing !!
Rob FletcherPosted Jul 28, 2020, 4:48 AM EDT
You should update your phone example. Nokia and Blackberry? Some would say, "what are those," now.
Dinesh GabhanePosted Nov 7, 2019, 3:26 AM EST
Very Nice Article
Rupesh VermaPosted Sep 29, 2019, 9:10 PM EDT
Very nice article. i have learn a lot from it
Amit AgarwalPosted Aug 23, 2019, 10:50 PM EDT
Nice explanation.....
Rohit GhoshPosted Jun 26, 2019, 5:17 PM EDT
Very nice article for me and for a beginner
Reshma BhalekarPosted Mar 11, 2019, 12:31 AM EDT
Very nice article and real-life examples... Keep it up..
Udit GandhiPosted Jan 9, 2019, 11:19 PM EST
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 17, 2018, 9:42 PM EDT
Super explanation sir.....
Patel SoniyaPosted May 28, 2018, 12:09 AM EDT
Great Explanation...........
Amol KumbhkarnaPosted Apr 13, 2018, 2:17 AM EDT
Great article .. Keep It Up...
Laxmidhar SahooPosted Dec 2, 2017, 1:28 AM EST
This will helpfull to my blog C# Class
Mayur PadhiyarPosted Jun 30, 2017, 4:58 PM EDT
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, 3:09 AM EDT
Really a great artical easily understandable. .
Vaibhav PatilPosted Jun 13, 2017, 8:19 AM EDT
Nicely and simply explained. Recommend for beginners.
prabhakar srivastavaPosted Jun 13, 2017, 4:31 AM EDT
Great Post Manish Cheers!
Nilankar GhoshPosted May 18, 2017, 9:23 PM EDT
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, 1:16 AM EDT
Sir,Nice explanation.Can you please tell me in one line. why we use oops in programming language.
Twana IsmaelPosted Jan 29, 2017, 10:15 PM EST
The article was very good but i couldn't download the ebooks ..
Tejaswi KhandarePosted Jan 13, 2017, 11:21 PM EST
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, 2:33 AM EST
Thank you very much for sharing.
sumit yadavPosted Dec 15, 2016, 2:50 AM EST
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, 3:17 PM EST
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, 10:43 AM EDT
Nice
rehan khanPosted Sep 8, 2016, 12:36 PM EDT
U r just Awesome...! :)
Ramesh PalaniappanPosted Aug 18, 2016, 4:19 AM EDT
Nice
kalu singh raoPosted Jul 7, 2016, 4:40 AM EDT
Nice...
praveen kumarPosted Jun 16, 2016, 4:19 AM EDT
thank you
sachith wickramaarachchiPosted Jun 13, 2016, 10:36 AM EDT
Nice Post.
vishal reddy k vPosted May 28, 2016, 7:05 AM EDT
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, 12:55 AM EDT
Nice Post. Abstraction is too good.
sachith wickramaarachchiPosted May 10, 2016, 10:00 AM EDT
Good post
monil thakorPosted Mar 11, 2016, 1:24 AM EST
Accha he...
Pawan TiwariPosted Jan 27, 2016, 12:15 AM EST
Abstraction example is outstanding....
Phaneendra ChakravaramPosted Jan 23, 2016, 5:00 AM EST
tq
Uday Bhan SinghPosted Oct 21, 2015, 1:45 AM EDT
once again thanks Manish Agrahari ji
joe rozarioPosted Oct 17, 2015, 9:57 PM EDT
nice one. please make Polymorphism better.
Santosh MPosted Oct 12, 2015, 3:58 AM EDT
nice explanation
Nihal AhmedPosted Sep 30, 2015, 3:41 AM EDT
nice one
santosh yadavPosted Aug 19, 2015, 12:20 PM EDT
nice
Amit HabuPosted Aug 13, 2015, 6:59 PM EDT
Thanks for explaining in simple and real world examples, very nice.
Manasi JarandePosted Jul 7, 2015, 8:20 PM EDT
short and sweet
balaji jayamangalaPosted Jul 6, 2015, 3:59 AM EDT
super
balaji jayamangalaPosted Jul 6, 2015, 3:59 AM EDT
super
Rajendra TaradalePosted Jul 2, 2015, 1:30 AM EDT
good explained
Kalai SelvanPosted Jun 16, 2015, 8:45 PM EDT
Good explanation!!!
vishal boradePosted May 27, 2015, 2:10 AM EDT
nice one
Gowtham RajamanickamTOP 100Posted May 19, 2015, 9:17 PM EDT
easy to learn
Gowtham RajamanickamTOP 100Posted May 19, 2015, 9:17 PM EDT
nice presentation
Upendra Pratap ShahiPosted May 10, 2015, 11:06 PM EDT
nice..
kazi salimullahPosted May 6, 2015, 2:31 AM EDT
Very nice presentation of basic OOP shortly,thanks.
Rohidas KadamPosted Mar 14, 2015, 3:11 AM EDT
Thanks for useful information
Web DeveloperPosted Dec 23, 2014, 7:09 AM EST
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, 7:07 AM EST
Great explanation. thanks.
Priyank PandyaPosted Oct 9, 2014, 9:29 PM EDT
its nice to understand
Naitik JaniPosted Oct 9, 2014, 12:30 AM EDT
Good Explaination..
Pooja SharmaPosted Sep 19, 2014, 10:32 PM EDT
Nice one
Dharmendra kuma yadavPosted Aug 27, 2014, 10:09 AM EDT
easy to understand and explain also easy
Mayur NabedaPosted Jul 30, 2014, 12:11 PM EDT
Good One, Can you go for interface also ??
Satheesh Kumar PilliPosted Jul 1, 2014, 4:47 AM EDT
Good article with real time examples
Ganapathi GPosted Jun 27, 2014, 10:05 AM EDT
Good comparison to understand easily.
Sonu RajPosted May 31, 2014, 7:34 PM EDT
very Nice article about the difference between abstraction and Encapsulation
Muhammad JawwadPosted May 21, 2014, 12:29 PM EDT
NICE (Y)
naveen dusaPosted Apr 5, 2014, 11:54 PM EDT
Very good explanation for beginners thanks.. :)
Surya PrakashPosted Mar 25, 2014, 11:45 PM EDT
good and neat explanation , it's easy to understand
prashant bhajantriPosted Mar 25, 2014, 2:56 AM EDT
good explanation with real time examples :)
piyush rajPosted Feb 27, 2014, 7:42 PM EST
awesomes explaination
kanna kannaPosted Dec 29, 2013, 7:16 PM EST
Very Nice Article
hari krishnanPosted Nov 24, 2013, 8:17 PM EST
Nice understandable Article...Thanks!!!!!!
Hitesh chotaliyaPosted Oct 1, 2013, 3:12 AM EDT
Very Nice and Good Understanding Article
Mahesh AllePosted Sep 30, 2013, 6:31 AM EDT
Simple, very clear to understand. Good Job.
Rohatash KumarTOP 100Posted Sep 30, 2013, 4:40 AM EDT
Good Article.
Lax LaxPosted Sep 30, 2013, 3:13 AM EDT
Thank you for this great article. It made things much clear for me.
Manish AgrahariPosted Jun 3, 2013, 6:42 AM EDT
@Mahesh Chand Sir:- Thank You sir... I am pleased to have your comment on my post..
Manish AgrahariPosted Jun 3, 2013, 6:41 AM EDT
Thanks a lot Dinesh Beniwal, Kundan Kumar and Isman Subarkah..
Isman SubarkahPosted May 31, 2013, 8:44 AM EDT
great article, after read this article, i feel that i have better understanding about object oriented programming.
Mahesh ChandTOP 10Posted May 29, 2013, 4:43 AM EDT
I love your "Life Funda" posted on your profile. Very nice!
Kundan KumarPosted May 29, 2013, 3:58 AM EDT
Very nice article.
Dinesh BeniwalTOP 10Posted May 29, 2013, 3:52 AM EDT
Good Start Manish, Welcome to the C# Corner.