menu

Wednesday, August 28, 2013

Inheritance in C#

using System;
namespace Inheritance
{
    interface I1
    {
        void Fun();
    }
    public abstract class A
    {
        // Implemented function can also be marked as virtual
        public virtual void Fun()
        {
            Console.WriteLine("I1::Fun()");
        }
        public abstract void Fun1();
        public virtual void Fun2()
        {
            Console.WriteLine("C1::Fun()");
        }
    }
    public class C1 : A
    {
        // Overriding abstract function of class A
        public override void Fun1()
        {
            Console.WriteLine("C1::Fun1()");
        }
        // Overriding virtual function of class A
        public override void Fun2()
        {
            Console.WriteLine("C1::Fun2()");
        }
    }
    public class C2 : C1
    {
        // Overriding virtual function of class A
        public override void Fun()
        {
            Console.WriteLine("C2::Fun()");
        }
        // Overriding abstract function of class A
        public override void Fun1()
        {
            Console.WriteLine("C2::Fun1()");
        }
        // Overriding virtual function of class A
        public override void Fun2()
        {
            Console.WriteLine("C2::Fun2()");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {

            Console.ReadKey();
        }
    }
}


No comments:

Post a Comment