Inherited member methods and fields : Class Definition : Class C# Examples


C# Examples » Class » Class Definition »

 

Inherited member methods and fields









    
using  System;

class  BaseClass                                                      
{
      public  string  Field1  =  "base  class  field";
      public  void  Method1(string  value)
      {
            Console.WriteLine("Base  class        --  Method1:  {0}",  value);
      }
}

class  DerivedClass  :  BaseClass                        
{
      public  string  Field2  =  "derived  class  field";
      
      public  void  Method2(string  value)
      {
            Console.WriteLine("Derived  class  --  Method2:  {0}",  value);
      }
}

class  MainClass
{
      static  void  Main()
      {
            DerivedClass  oc  =  new  DerivedClass();
            oc.Method1(oc.Field1);                              //  Base  method  with  base  field
            oc.Method1(oc.Field2);                              //  Base  method  with  derived  field
            oc.Method2(oc.Field1);                              //  Derived  method  with  base  field
            oc.Method2(oc.Field2);                              //  Derived  method  with  derived  field
      }
}
    
   
  
   



Output

Base class    -- Method1: base class field
Base class    -- Method1: derived class field
Derived class -- Method2: base class field
Derived class -- Method2: derived class field


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Class
» Class Definition