An example of inheritance-related name hiding : Class Inheritance : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Class Inheritance »

 

An example of inheritance-related name hiding









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// An example of inheritance-related name hiding. 
 
using System; 
 
class A { 
  public int i = 0; 
} 
 
// Create a derived class. 
class B : A { 
  new int i; // this i hides the i in A 
 
  public B(int b) { 
    i = b; // i in B 
  } 
 
  public void show() { 
    Console.WriteLine("i in derived class: " + i); 
  } 
} 
 
public class NameHiding { 
  public static void Main() { 
    B ob = new B(2); 
 
    ob.show(); 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Class Inheritance