Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    An illustration of virtual and new methods - More simplified.Lecture 7 - slide 35 : 40
Program 4
using System;

class A {
  public virtual void  N(){Console.WriteLine("N in A");}
  public void          P(){Console.WriteLine("P in A");}
}

class B: A{
  public override void N(){Console.WriteLine("N in B");}
  public new void      P(){Console.WriteLine("P in B");}
}

class Client {
  public static void Main(){
    A ab = new B();

    ab.N();         // The dynamic type controls. Prints: N in B
    ab.P();         // The static type controls.  Prints: P in A
  }
}