Ishu_15hu

Method Overriding/virtual method C#

Dec 1st, 2020
403
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;  
  2. public class Base{  
  3.     public virtual void func(){  
  4.         Console.WriteLine("Base Class method...");  
  5.     }  
  6. }  
  7. public class Derived: Base  
  8. {  
  9.     public override void func()  
  10.     {
  11.         base.func();// 'base.func()' is called to get base class methode in derived class
  12.         Console.WriteLine("Derived class method...");  
  13.     }  
  14. }  
  15. public class Program  
  16. {  
  17.     public static void Main()  
  18.     {  
  19.         Derived d = new Derived();  
  20.         d.func();  
  21.     }  
  22. }  
RAW Paste Data