Abstract class

Abstract class can have abstract members.

Abstract method have no method body.

Abstract class declares a blue print for a type.

Abstract class cannot be instantiated.


using System;
abstract class Shape
{
    public abstract int GetArea();

}

class Rectangle : Shape
{
    public int width;
    public int height;

    public override int GetArea()
    {
        return width * height;
    }
}

class Program
{
    static void Main(string[] args)
    {

        Rectangle r = new Rectangle();
        r.width = 5;
        r.height = 6;
        Console.WriteLine(r.GetArea());

    }
}

The output:


30
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.