An example of inheritance-related name hiding. : Name Hiding « Class « C# / CSharp Tutorial






using System; 
 
class BaseClass { 
  public int i = 0; 
} 
 
// Create a derived class. 
class DerivedClass : BaseClass { 
  new int i; // this i hides the i in BaseClass 
 
  public DerivedClass(int b) { 
    i = b; // i in DerivedClass 
  } 
 
  public void show() { 
    Console.WriteLine("i in derived class: " + i); 
  } 
} 
 
class MainClass { 
  public static void Main() { 
    DerivedClass ob = new DerivedClass(2); 
 
    ob.show(); 
  } 
}
i in derived class: 2








7.26.Name Hiding
7.26.1.An example of inheritance-related name hiding.
7.26.2.Using base to overcome name hiding.
7.26.3.Call a hidden method