Introduction
In the Object Oriented Programming [OOPs], we only talk about in terms of object. In programming language like C#, we use logically to store data as class, struct etc. but physically these are objects.
Here are the features of OOPs.
Class
Class is nothing but a blue print. It is a way to represent the data. It contains member variable to store the data, member functions to perform operation. It does occupy any space in memory whether it is logical representation of data. When we create instance of class using the new keyword, the object of class take the space in memory.
Example of Class
- public class Customer
- {
- //Fields, properties, methods and events go here...
- }
Encapsulation
Encapsulations mean encapsulate the data or bind the data or we can also say wrap the data in one unit. In the OOPs programming we use the classes to store the variables, events, function, etc. So, basically here we are binding the data in one group which is called class. The process of wrapping up of data in the single unit is called data encapsulation.
Example of Encapsulation
- class Counter
- {
- private int Count;
- public Counter()
- {
- Count = 0;
- }
- public void setCount(int newVal)
- {
- Count = newVal;
- }
- public int getCount()
- {
- return Count;
- }
- }
Abstraction
Hiding the data to outer world is called Abstraction. It means sometimes it is required to hide some data to outer logic, here abstraction comes in demand. For example, if we want to hide a member variable and create it private, then it will not be accessible to the outer world. It is only accessible to class. So, this is called Abstraction. It is used to provide the security of data.
Example of Abstraction
- public abstract class ShapesClass
- {
- abstract public int Area();
- }
- public class Square : ShapesClass
- {
- int side = 0;
- public Square(int n)
- {
- side = n;
- }
- // Area method is required to avoid
- // a compile-time error.
- public override int Area()
- {
- return side * side;
- }
- static void Main()
- {
- Square sq = new Square(12);
- Console.WriteLine("Area of the square = {0}", sq.Area());
- }
- }
Inheritance
Inheriting the features of existing parent is called Inheritance. In C#, when we create a new class from an existing class and inherit all the features of parent class in the child class, then we can say inheritance is happening.
Reusability is a main concern of inheritance. The class, whose functionality is going to inherit is called Parent class or base class or super class and the class which inherit the feature of base class is called child class, derived class.
Example of Inheritance
- public class Animal
- {
- public virtual void Greet()
- {
- Console.WriteLine("This is an animal");
- }
- }
- public class Dog : Animal
- {
- public override void Greet()
- {
- Console.WriteLine("This is a dog!");
- }
- }
Polymorphism
Polymorphism means one name, many forms. We can achieve Polymorphism with the the help of overloading and overriding concepts. There are two type of polymorphism, first one is compile time polymorphism and second one is run time polymorphism. We use virtual and override keyword to achieve polymorphism.
Example of polymorphism
- class Shape
- {
- protected int width, height;
- public Shape(int a = 0, int b = 0)
- {
- width = a;
- height = b;
- }
- public virtual int area()
- {
- Console.WriteLine("Parent class area :");
- return 0;
- }
- }
- class Rectangle : Shape
- {
- public Rectangle(int a = 0, int b = 0)
- : base(a, b)
- {
- }
- public override int area()
- {
- Console.WriteLine("Rectangle class area :");
- return (width * height);
- }
- }
Hope you enjoyed this article.

Mukesh KumarPosted Oct 18, 2015, 5:39 AM
Thanks Sir
Santhakumar MunuswamyPosted Oct 18, 2015, 5:21 AM
Good one
Mukesh KumarPosted Oct 16, 2015, 5:46 AM
Thanks Suman
Suman VermaPosted Oct 16, 2015, 5:46 AM
Nice article
Yaduveer SainiPosted Oct 16, 2015, 5:39 AM
Good job
Banketeshvar NarayanPosted Oct 16, 2015, 3:34 AM
Great job.. Keep it up!
Mukesh KumarPosted Oct 8, 2015, 1:39 AM
Thank you sir
RakeshPosted Oct 8, 2015, 1:35 AM
Good one
Mukesh KumarPosted Oct 8, 2015, 1:32 AM
Thanks Ankit
Ankit BansalPosted Oct 8, 2015, 12:50 AM
nice one..
Mukesh KumarPosted Oct 7, 2015, 11:45 PM
Thanks sir
Muhammad Aqib ShehzadPosted Oct 7, 2015, 3:18 PM
good
Mukesh KumarPosted Oct 7, 2015, 7:39 AM
Thanks Harshad
Harshad PansuriyaPosted Oct 7, 2015, 7:20 AM
Nice one
Mukesh KumarPosted Oct 7, 2015, 5:54 AM
Thanks Nilesh
Mukesh KumarPosted Oct 7, 2015, 5:54 AM
Thanks Abhishek.. I will try to implement these thing in my next articles... Thanks for suggesting good things
Nilesh JadavPosted Oct 7, 2015, 5:48 AM
Nice !!
Abhishek JaiswalPosted Oct 7, 2015, 5:29 AM
All over your article looks good, but still I wanna share a tip with you- From next time onwards try to elaborate your Example, like how the functioning going forward and the other things. This will increase the readability of your article and will make it easier to understood. Cheers!! :)
Mukesh KumarPosted Oct 7, 2015, 5:19 AM
Thanks
Rajeesh MenothPosted Oct 7, 2015, 5:10 AM
Nice Share...