Created
March 17, 2015 06:34
-
-
Save dnasca/9860c9ca8d2ac398ed6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| /* Method Overriding and Method Hiding | |
| * | |
| * In method overriding, a base class reference variable pointing to a child object will invoke the overriden method in the child class | |
| * | |
| * In method hiding, a base class reference variable pointing to a child class object will invoke the hidden method in the base class | |
| * | |
| */ | |
| public class BaseClass | |
| { | |
| public virtual void Print() | |
| { | |
| Console.WriteLine("I am the BaseClass Print Method"); | |
| } | |
| } | |
| public class DerivedClass : BaseClass | |
| { | |
| public override void Print() //we are overriding the implimentation of the BaseClass Print method | |
| //if we wanted to HIDE this method, we would use the 'new' modifier instead of override | |
| { | |
| Console.WriteLine("I am the Derived Class Print Method"); | |
| } | |
| } | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| BaseClass B = new BaseClass(); //a base class reference variable can point to a derived class object | |
| B.Print(); //overriden version of Print method called | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment