Search

Sunday, February 9, 2014
One comments

How to access base class constructor from derived class in C# Programming

10:27 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.

The base class that is accessed is the base class specified in the class declaration. For example, if you specify class childclass : baseclass, the members of baseclass are accessed from childclass, regardless of the base class of baseclass.

Lets take an simple example 

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

namespace ConsoleApplication8
{
    class Program
    {
        public Program ()
        {
            Console .WriteLine ("Base class Constructor");
        }
       
        static void Main(string[] args)
        {

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

        }
        
    }
    class abc : Program
    {
        public abc():base()
        {

            Console.WriteLine("Child Class");

          
        }
    }
}

Code Generate the following output 

How to access base class constructor from derived class in C# Programming

Protected by Copyscape Online Copyright Protection Software

1 comments :

  1. get any kind of programming help online at very cheap price like c , c++, c# programming all you can get online by highly qualified experts

    ReplyDelete

 
Toggle Footer
Top