abstract

Summary

The abstract modifier is used to declare an abstract class or a method that must be implemented by derived classes.

Syntax

abstract statement

Parameters

statement
The statement to declare 'abstract'.

Description

The abstract modifier, when used on a method or property, declares it as an abstract method or property, and, therefore, the method/property must be implemented by derived classes. Abstract methods and properties have no implementation themselves.

The abstract modifier can only be used on class declarations or inside abstract classes, which are classes declared with the abstract modifier. Abstract classes cannot be instantiated, and derived classes of an abstract base class must implement all abstract methods and properties of the abstract base class.

Derived classes trying to implement an abstract method must use the override or final keyword.

Examples

Implementing an Abstract Method
1
2
3
4
5
6
7
8
9
10
11
12
abstract class Shape
{
    public abstract int area();
}
class Rectangle : Shape
{
    private int length, width;
 
    public override int area() {
        return length * width;
    }
}

See Also

Share

HTML | BBCode | Direct Link