Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    An illustration of "non-virtual variable access".Lecture 7 - slide 40 : 40
Program 1
using System;

public class A{
  public int v = 1;
}

public class B: A{
  public new int v = 5;
}

public class App{
  public static void Main(){   // Static type    Dynamic type
    A anA =      new A(),      //     A             A
      anotherA = new B();      //     A             B
    B aB =       new B();      //     B             B
  
    Console.WriteLine(
     "{0}",
       anA.v               // 1
       + anotherA.v        // 1    
       + ((B)anotherA).v   // 5
       + aB.v              // 5
    );
  }
}