Breaking News
yeni film izle hd film seyret film izle

Polymorphism in C#

Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details.
One of the basic concepts of object oriented software development is polymorphism. The word polymorphism (from the Greek meaning “having multiple forms”) in OOP 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.
When a derived class inherits from a base class, it gains all the methods, fields, properties and events of the base class. To change the data and behavior of a base class, you have two choices: Either you can replace the base member with a new derived member, or you can override a virtual base member.
Replacing a member of a base class with a new derived member requires the new keyword. If a base class defines a method, field, or property, the new keyword is used to create a new definition of that method, field, or property on a derived class. The new keyword is placed before the return type of a class member that is being replaced.
When the new keyword is used, the new class members are called instead of the base class members that have been replaced. Those base class members are called hidden members. Hidden class members can still be called if an instance of the derived class is cast to an instance of the base class.
Polymorphism has 2 types:
1. Compile time Polymorphism (Static Polymorphism)

2. Runtime Polymorphism (Dynamic Polymorphism)

1 Compile time polymorphism:
Compile time polymorphism is also called overloading and it have 3 types:
i) Constructor overloading (i.e. with same constructor name and different no of arguments or different data types or both)
ii) Function overloading (i.e. with same function name and different no of arguments or different data types or both)
iii) Operator overloading: example: String s = “Ujjwal”; s = s + “Mehta”;
2. Runtime time polymorphism:
Runtime polymorphism is achieved by overriding parent class method. This is called Dynamic method dispatch.
To Download Polymorphism example Click here.
To view downloaded examples, Please Ensure that .NET Framework is installed on your system.

Check Also

Exceptions In C#

System.Exception is the base class for all other exceptions. Below this level are the System.ApplicationException …