An example of inheritance-related name hiding. : Name Hiding : Class C# Examples


C# Examples » Class » Name Hiding »

 

An example of inheritance-related name hiding.









    
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();  
    }  
}
    
   
  
   



Output

i in derived class: 2


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Name Hiding