Overriding a virtual method in a generic class : Generic Hiearchy : Generic C# Examples


C# Examples » Generic » Generic Hiearchy »

 

Overriding a virtual method in a generic class









    
using  System;    
    
class  Gen<T>  {      
    protected  T  ob;      
          
    public  Gen(T  o)  {      
        ob  =  o;      
    }      
      
    public  virtual  T  getob()  {      
        Console.Write("Gen's  getob():  "  );    
        return  ob;      
    }      
}      
    
class  Gen2<T>  :  Gen<T>  {    
    
    public  Gen2(T  o)  :  base(o)  {    }    
        
    public  override  T  getob()  {      
        Console.Write("Gen2's  getob():  ");    
        return  ob;      
    }      
}    
      
class  MainClass  {      
    public  static  void  Main()  {      
        Gen<int>  iOb  =  new  Gen<int>(88);    
  
        Console.WriteLine(iOb.getob());    
  
        iOb  =  new  Gen2<int>(99);      
  
        Console.WriteLine(iOb.getob());    
    }  
}
    
   
  
   



Output

Gen's getob(): 88
Gen2's getob(): 99


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Generic
» Generic Hiearchy