Wednesday, March 11, 2015

C# program that uses abstract class

using System;

abstract class Test
{
    public int _a;
    public abstract void A();
}

class Example1 : Test
{
    public override void A()
    {
 Console.WriteLine("Example1.A");
 base._a++;
    }
}

class Example2 : Test
{
    public override void A()
    {
 Console.WriteLine("Example2.A");
 base._a--;
    }
}

class Program
{
    static void Main()
    {
 // Reference Example1 through Test type.
 Test test1 = new Example1();
 test1.A();

 // Reference Example2 through Test type.
 Test test2 = new Example2();
 test2.A();
    }
}

Output

Example1.A
Example2.A

No comments:

Post a Comment