Object oriented features in C#.Net

C#.Net has below object oriented features.

  1. Encapsulation
  2. Inheritance
  3. Abstraction
  4. Method Overloading

Encapsulation in C#.Net

Everything in C# Application is encapsulated. A project consists of namespaces. Namespaces encapsulates classes, interfaces etc. Each class encapsulates its members – variables and methods. A class can not access the private members of other classes.

Inheritance in C#.Net

Inheritance is the mechanism in which protected and public members of the base class become the members of the derived class. So if you have a class Car with public fields make and model and there is another class ToyotaCar which inherits the class Car, then the fields make and model will be members of the ToyotaCar class as well.

Abstraction in C#.Net

Abstraction is the mechanism in which we just specify what behavior is expected out of the class. But implementations might vary.

For example – we know that all browsers allow you to open a website, navigate back and forward. So we know the standard operations of each browser but the implementation of these operations varies for each browser. With the help of Abstraction, we can specify this standard behavior of the class through abstract methods or interfaces.

Method overloading in C#.Net

With method overloading, we can change the implementation of any inherited method in derived classes. This allows us to override the behavior of the base class.

You may also like...