TEP , The Engineering Projects , Author Welcome! Syed Zain Nasir Mechatronics Engineer TEP , The ENgineering Projects , TEP Badge TEP , The Engineering Projects , Ratting Background 7.5 7.5/10
TEP , The Engineering Projects , Rating Percentage Background Reputation Score 55 / 100
Introduction to Polymorphism in C#,Polymorphism in C#,Polymorphism C#, C# Polymorphism
TEP , The Engineering Projects , Boxes

Introduction to Polymorphism in C#

TEP , THe Engineering Projects , Shares 2.5K Views
TEP , The ENgineering Projects , Reaction 40
TEP , The ENgineering Projects , Reaction 700
TEP , The ENgineering Projects , Reaction 60
TEP , The ENgineering Projects , Reaction 25
TEP , The ENgineering Projects , Reaction 60
TEP , The Engineering Projects , Pintrest TEP , The Engineering Projects , Pintrest TEP , The Engineering Projects , Pintrest TEP , The Engineering Projects , Pintrest TEP , The Engineering Projects , Pintrest
Shares: 691
TEP , The Engineering Projects , PCBWAY
Introduction to Polymorphism in C#,Polymorphism in C#,Polymorphism C#, C# Polymorphism
Hello friends, I hope you all are having fun. In today's tutorial, we will have a look at Introduction to Polymorphism in C#. It's our 16th tutorial in C# series and polymorphism is considered as a main pillar of object oriented programming. In our previous tutorial, we have seen a detailed Introduction to Inheritance in C# and along with it, we have also discussed How to hide a Method in Parent Class, if the same method exists in Child class. This Method Hiding is actually the basis of Polymorphism, so let's discuss it out in detail:

Introduction to Polymorphism in C#

  • Polymorphism in C# enables the user to invoke a Child Class Method & override the Parent Class Method, using a Parent Class Reference variable.
  • In our previous lecture on Inheritance, we have also discussed method hiding and our last code is shown in below figure:
Introduction to Polymorphism in C#,Polymorphism in C#,Polymorphism C#, C# Polymorphism
  • In the above code, you can see that we have used method hiding by using new keyword with ChildClass Method.
  • So, now instead of hiding the method let's override it and have a look at the results:
Introduction to Polymorphism in C#,Polymorphism in C#,Polymorphism C#, C# Polymorphism
  • In the above figure, you can see that I have used virtual keyword with Parent Class Method.
  • Moreover, instead of new keyword, I have used override keyword with Child Class Method.
  • I have used the same reference variables as I did for Method Hiding code, but here in the third case, the child class method is called.
  • So, in Polymorphism, if the Child Class is involved in reference variable, then it will always override the Parent Class Method and will use the Child Class Method.
  • So, we can say that if we want to completely override any function in Parent Class, then we need to add virtual keyword in its definition.
  • This virtual Parent Class Method will always get override by any Base Class Method, which has the same name and has override keyword in its definition.
  • But if we want to invoke the virtual Parent Class Method, then we have to use Parent Class reference variable.
  • So, this third variable PC2 is the main difference between Method Hiding & Method Overriding (Polymorphism).
So, that was all about Polymorphism in C# and if you have got the Method Hiding then it won't be much of an issue for you. In the next lecture, we will have a look at Introduction to Structures in C#. Till then take care & have fun !!! :)
TEP , The Engineering Projects , Tags
Introduction to Polymorphism in C#
Polymorphism in C#
Polymorphism C#
C# Polymorphism
TEP , The Engineering Projects , Comments

Write a Comment

TEP , The Engineering Projects , WordPress TEP , The Engineering Projects , Google TEP , The Engineering Projects , Twitter TEP , The Engineering Projects , Facebook TEP , The Engineering Projects , User
TEP , The Engineering Projects , Robot
TEP , The Engineering Projects , Comments Comments on ‘’ Introduction to Polymorphism in C# ‘’ (0)
TEP , The Engineering Projects , About TEP , The Engineering Projects , About Shadow

Top PCB Design Service

PCBA
TEP , The Engineering Projects , JLCPCB
PCB
TEP , The Engineering Projects , JLCPCB
TEP , The Engineering Projects , About TEP , The Engineering Projects , About Shadow

Embedded Tools

ARDINO TEP , The Engineering Projects , JLCPCB
TEP , The Engineering Projects , About TEP , The Engineering Projects , About Shadow

Subscribe Now !!!

Learn Free Pro Tricks

TEP , The Engineering Projects , Mail Receive Quality Tutorials Straight in your Inbox by Submitting your Email ID Below
TEP , The Engineering Projects , Mail TEP , The Engineering Projects , Mail Shadow
TEP , The Engineering Projects , Mail Robot TEP , The Engineering Projects , Mail Robot Shadow TEP , The Engineering Projects , Mail Robot Shadow
TEP , The Engineering Projects , About TEP , The Engineering Projects , About Shadow

Engineering Books

TEP , The Engineering Projects , Arduino Programming Book
SALE $20
Text Book for arduino $20
TEP , The Engineering Projects , Rating Stars (5.0)
TEP , The Engineering Projects , Arduino Programming Book
SALE $20
Text Book for Raspberry Pi $20
TEP , The Engineering Projects , Rating Stars (3.0)
TEP , The Engineering Projects , Arduino Programming Book
SALE $20
Text Book for arduino $20
TEP , The Engineering Projects , Rating Stars (4.7)
TEP , The Engineering Projects , Arduino Programming Book
SALE $20
Text Book for Raspberry Pi $20
TEP , The Engineering Projects , Rating Stars (5.0)
TEP , The Engineering Projects , TEP Robot TEP , The Engineering Projects , TEP Robot Shadow TEP , The Engineering Projects , TEP Robot Shadow
TEP , The Engineering Projects , About TEP , The Engineering Projects , About Shadow

Categories

TEP , The Engineering Projects , Arduino
TEP , The Engineering Projects , Notification 20K
TEP , The Engineering Projects , Tick 900
TEP , The Engineering Projects , Views 900
TEP , The Engineering Projects , Comments 20K
TEP , The Engineering Projects , Arduino
TEP , The Engineering Projects , Notification 20K
TEP , The Engineering Projects , Tick 900
TEP , The Engineering Projects , Views 900
TEP , The Engineering Projects , Comments 20K
TEP , The Engineering Projects , Arduino
TEP , The Engineering Projects , Notification 20K
TEP , The Engineering Projects , Tick 900
TEP , The Engineering Projects , Views 900
TEP , The Engineering Projects , Comments 20K
TEP , The Engineering Projects , Arduino
TEP , The Engineering Projects , Notification 20K
TEP , The Engineering Projects , Tick 900
TEP , The Engineering Projects , Views 900
TEP , The Engineering Projects , Comments 20K
TEP , The Engineering Projects , Arduino
TEP , The Engineering Projects , Notification 20K
TEP , The Engineering Projects , Tick 900
TEP , The Engineering Projects , Views 900
TEP , The Engineering Projects , Comments 20K