Overriding and Overloading in C#
Hi, today we going to learn all about the overloading and overriding concepts in c# with example.
Description:
Before going to the overloading and overriding, we have to learn polymorphism, which is the one of the important concept of oops.
Poly means 'many' , morph means 'forms' hence, hence the polymorphism means ability to take many forms.
In polymorphism we can declare the same method name with different arguments in a class and same method name with same arguments in different classes. The polymorphism has the ability to provide different method implementation and that are with the same name.
We have two types of polymorphism, namely
Overloading and Overriding
Overloading:
In overloading the same name with different signature can be used, thus provides us the benefit of using same name with different tasks. This is also called as compile time polymorphism .
Overriding:
In overriding the method name have same signature can be used in many class with the reference, hence at the runtime only the method and its signatures will be known to the clr.
This is also known as runtime polymorphism.
Overriding an be performed using virtual and override keywords.
Initially we need to create a method with the name virtual and when using the same method name we have to use override keyword.
*signature = parameters
example of overloading:
Example of overriding:
for more information refer my other posts too!
Thank you!
Hi, today we going to learn all about the overloading and overriding concepts in c# with example.
Description:
Before going to the overloading and overriding, we have to learn polymorphism, which is the one of the important concept of oops.
Poly means 'many' , morph means 'forms' hence, hence the polymorphism means ability to take many forms.
In polymorphism we can declare the same method name with different arguments in a class and same method name with same arguments in different classes. The polymorphism has the ability to provide different method implementation and that are with the same name.
We have two types of polymorphism, namely
Overloading and Overriding
Overloading:
In overloading the same name with different signature can be used, thus provides us the benefit of using same name with different tasks. This is also called as compile time polymorphism .
Overriding:
In overriding the method name have same signature can be used in many class with the reference, hence at the runtime only the method and its signatures will be known to the clr.
This is also known as runtime polymorphism.
Overriding an be performed using virtual and override keywords.
Initially we need to create a method with the name virtual and when using the same method name we have to use override keyword.
*signature = parameters
example of overloading:
Example of overriding:
for more information refer my other posts too!
Thank you!
No comments:
Post a Comment