- One of the fundamental concepts of object oriented software development is polymorphism. The term polymorphism (from the Greek meaning "having multiple forms") in object oriented is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow a variable to refer to more than one type of object.
- In other words, the ability of different objects to respond to the same message in different ways is called Polymorphism. Whenever an entity can change its definition based on the argument values passed to the entity then it is said to be Polymorphism; where an entity can be a method or an operator.
Types of Polymorphism
There are two types of Polymorphism. They are...- Static Polymorphism:
- Which method is to be called is decided at compile-time only. Method Overloading is an example of Static Polymorphism.
- Method overloading is a concept where we use the same method name many times in the same class, but different parameters. Depending on the parameters we pass, it is decided at compile-time only. The same method name with the same parameters is an error and it is a case of duplication of methods which c# does not support. In Static Polymorphism decision is taken at compile time.
- This is also known as early binding or Compile time Polymorphism.
- Dynamic Polymorphism.:
- Dynamic Polymorphism is a concept of by which a call to an overridden function is resolved at a Run-Time (not at Compile-time) if a base Class contains a method that is overridden. Method overriding means having two or more methods with the same name, same signature but with different implementation. In this process, an overridden method is called through the reference variable of a superclass, the determination of the method to be called is based on the object being referred to by reference variable.
- This is also known as late binding or Runtime Polymorphism.
Polymorphism in c #
C# supports two types of overloading…
- Method overloading:
- Method overloading is a concept of writing more than one method with same name and different types of arguments.
- Method Overloading is an example of Compile Time Polymorphism.
- Operator overloading::
- Whenever predefined operator is not providing users requirement, then it need to be overloaded.
- It is a concept of extending the functionality of an existing operator.
- Overloaded operator must be declared as static.
0 comments :
Post a Comment