Search

Sunday, February 9, 2014
0 comments

How to call base class methods from derived class in c# programming

9:01 PMSunday, February 9, 2014
Its a concepts of inheritance, child class derived from base class or you can say, a class inherits property from other class known as derived class or child class.
This example cover, If you want to access base class method into child class, you should use base keyword for that. lets take an simple example to demonstrate of this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
       
        static void Main(string[] args)
        {

            abc obj = new abc();
            Console.ReadKey();

        }
        public void getg()
        {
            Console.WriteLine("base class");

        }
    }
    class abc : Program
    {
        public abc()
        {
            base.getg();
            Console.WriteLine("Child class");

          
        }
    }
}

Code generate the following output

How to call base class methods from derived class in c# programming

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top