Friday, 23 December 2016

Constructor

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

namespace OopsConcept
{
    class Constructor1
    {
        public Constructor1()
        {
            Console.WriteLine("constructr that have the no parameter");

        }
        //public Constructor1(string st)
        //{
        //    Console.WriteLine("constructr that have the  parameter {0}",st);

        //}
        public Constructor1(string st1, string st2)
        {
            Console.WriteLine("constructr that have the  parameter {0}&{1}", st1,st2);

        }
    
    }
     class ChildClass : Constructor1
    {
        public ChildClass()
            : base()
        {
            Console.WriteLine("Chuild  Class constructor with n parameter ");
        }
        //public ChildClass(string stchild1)
        //    : base(stchild1)
        //{
        //    Console.WriteLine("Child class cnstructr that have one string parameter{0}", stchild1);

        //}
        public ChildClass(string stchild1,string stChild2)
            : base(stchild1,stChild2)
        {
            Console.WriteLine("Child class cnstructr that have one string parameter{0} & {1}", stchild1, stChild2);

        }
    }
    public class Program1
    {
        public static void Maincons(string[] args)
        {
            Console.WriteLine("--------------------------Cnstructor Chaining strted here---------------------------------------");
            ChildClass objConstructor = new ChildClass ();
            ChildClass objCh2 = new ChildClass("Parameter1", "Parameter2");
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment