Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

09 June 2012

Accessing parent class data member in derived class using "base" keyword


In this code snippet we will discuss about how to access parent class data member from derived class.

If you want access parent class data member in the derived class then use ‘base’ keyword. In the derived class we can access all the data members (Public, Protected, internal, protected internal)  of parent class other than private data member.

Example:
  public class AcessBaseDataMember
    {
       public static void Main()
       {
           DerivedClass obj = new DerivedClass();
           obj.Get_Base_DataMember();
           obj.Get_Derived_DataMember();
           Console.Read();
       }
   
       
    }
    public class BaseClass
    {
        protected int i = 10;
    }
   public class DerivedClass:BaseClass
    {
         int i = 20;
        public void Get_Derived_DataMember()
        {
            Console.WriteLine("Derived class data member value is {0}",i);
        }
           public void Get_Base_DataMember()
        {
            Console.WriteLine("Base class data member value is {0}",base.i);
        }
    }
 
Output:

 

2 Comments:

Anonymous said...

Then it is important to apply general amount involving any medical cream like Clearasil on your own face.

Another available treatment option that can be done at home without a prescription is a topical ointment.
This sounds drastic but as long as you pay due care and attention
when carrying the task out the removal should happen without a hitch.



My web blog - Wart Removal

Anonymous said...

Mortgage expenses also include appraisals and commissions
paid. Robert Shumake's mission is to inform the public about mortgage fraud and real estate scams and to provide tips on how to avoid being a victim. Property - Hookp takes uses advanced link building and promotion tools to optimize your profile for search engine ranking.

Stop by my blog; Asunnot

Post a Comment