Interface can inherit from Interface,Abstract class can inherit from Interface

Interface can inherit from Interface,Abstract class can inherit from Interface and declare the method as abstract



namespace Reflection
{
    //Interface-1
    interface IB
    {
        void mymessageB();
    }

    //Interface-2 extending 1
    interface IA:IB
    {
        void mymessageA();
    }
    //Abstract extending Interface2 ,Interface1 , butimplementing only one interface1
    public abstract class Atest: IA
    {
        public abstract void mymessageA();
        public void mymessageB()
        {
            Console.WriteLine("My Message B");
        }
    }


    //Concrete class implementing the unimplemented Interface from inheriting abstract class
    //Abstract class can inherit interface but may or may not impement the interface
    //but a concrete class will have to print then
    class AConcrete :Atest
    {

        public override void mymessageA()
        {
            Console.WriteLine("My Message A");
        }

        //public override void mymessageB()
        //{
        //    Console.WriteLine("My Message B");
        //}
    }

class Program
    {
        static void Main(string[] args)
        {
            AConcrete a = new AConcrete();
            a.mymessageA();
            a.mymessageB();
            Console.ReadLine();


        }
    }

Comments

Popular posts from this blog

Authentication and Authorization in Web API -Part1

My Gardening Journey 6