-->

Sunday, February 9, 2014

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

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

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

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved