Advertisement

Polymorphism

By Bintu Chaudhary   Posted at  7:51:00 AM   Polymorphism

Home  »  C#  »  Polymorphism


     Originally polymorphism has been derived from two greek words poly which means many and morph which means forms. Thus stating multiforms or many faces.
   Hence polymorphism refers to the objects belonging to different classes responsd to the same function call but in different forms. For example, View function takes an argument and displays it on the screen.

  1. View("Welcome to my program");
  2. View(123.4);
  3. View(187524);

Therefore when the first method is called it will display Welcome to my program on the screen. When the second method is called by passing float argument it will display 123.4 and on the execution of the third method it will display 187524, which is an integer value.

  Overloading is the technique to implement the polymorphism.

Polymorphism and Virtual Methods

     A virtual method in C# specifies an implementaion of a method that can be polymorphically overridden derived method. A non-virtual method can't be polymorphically override in a Derived class. A virtual can be declared by using the keyword virtual as follows:



Output

















Output

About the Author

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: BT9

Back to top ↑
Connect with Me