Way to Programmer can Call Show Method

 Here, I created a interface IShow having one method Show(). We have two Class A, B inhrits from Interface IShow. In this Senario, how many way to programmer can show() method.

namespace ConsoleApplication

{

    interface IShow

    {

        void Show();

    }

    class A : IShow

    {

        public virtual void Show()

        {

            Console.WriteLine("Base Class function");

        }

        public void Show1()

        {

            Console.WriteLine("Base Class function");

        }

    }

    class B : A

    {

        public override void Show()

        {

            Console.WriteLine("Drived Class function");

        }

        public void Show2()

        {

            Console.WriteLine("Drived Class function");

        }

        static void Main(string[] args)

        {


            A A = new A();

            A.Show();

            B B = new B();

            B.Show();

            A A1 = new B();

            A1.Show();

            IShow S = new A();

            S.Show();

            IShow S1 = new B();

            S1.Show();

            Console.ReadKey(true);

        }

    }

}

 
Note : - Now you can see there is 5 way to call the Show method.

1. Create an object of A Class and Call the function

 A A = new A();
A.  Show();   

2. Create an object of B Class and Call the function

 B B = new B();
 B.Show();           

3. Create an A derived class object can be represented a its base class object. (Late Binding) and Call the function

 A A1 = new B();
 A1.Show();           

4. Create an Interface reference pointer of A Class and Call the function

 IShow S = new A();
 S.Show();           

5. Create an Interface reference pointer of B Class and Call the function

 IShow S1 = new B();
 S1.Show();           
 
Output :
 
Img1.jpg

Ebook Download
View all
Learn
View all