OOPS – Polymorphism and Inheritance (Dynamic Binding/Run Time Polymorphism)

This Article summarizes the following points written by Akhil Mittal :

  • In C#, We can equate an object of a base class to a derived class but not vice versa.
  • The override modifier is needed as the derived class methods will get first priority and be called upon.
  • These modifiers like new and override can only be used if the method in the base class is a virtual method. Virtual means that the base class is granting us permission to invoke the method from the derived class and not the base class. But, we have to add the modifier override if our derived class method has to be called.
  • If the base class object declared the method virtual and the derived class used the modifier override, the derived class method will get called. Otherwise, the base class method will get executed. Therefore for virtual methods, the data type created is decided at run time only.
  • All the methods not marked with virtual are non virtual, and the method to be called is decided at compile time, depending upon the static data type of the object.
  • An override method is a method that has the override modifier included on it. This introduces a new implementation of a method. We can’t use the modifiers such as new, static or virtual along with override. But abstract is permitted.

Read full article – http://www.codeproject.com/Articles/774578/Diving-in-OOP-Day-Polymorphism-and-Inheritance-Dyn

Hope this will help !!!

Jay Ganesh


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s