Export (0) Print
Expand All

abstract Modifier

Declares that a class must be extended or that the implementation for a method or property must be provided by a derived class.

abstract statement

Arguments

statement
Required. A class, method, or property definition.

Remarks

The abstract modifier is used for a method or property in a class that has no implementation or for a class that contains such methods. A class with abstract members cannot be instantiated with the new operator. You can derive both abstract and non-abstract classes from an abstract base class.

Methods and properties in classes and classes can be marked with the abstract modifier. A class must be marked as abstract if it contains any abstract members. Interfaces and members of interfaces, which are implicitly abstract, cannot take the abstract modifier. Fields cannot be abstract.

You may not combine the abstract modifier with the other inheritance modifier (final). By default, class members are neither abstract nor final. The inheritance modifiers cannot be combined with the static modifier.

Example

The following example illustrates a use of the abstract modifier.

// CAnimal is an abstract base class.
abstract class CAnimal {
   abstract function printQualities();
}
// CDog and CKangaroo are derived classes of CAnimal.
class CDog extends CAnimal {
   function printQualities() {
      print("A dog has four legs.");
   }
}
class CKangaroo extends CAnimal {
   function printQualities() {
      print("A kangaroo has a pouch.");
   }
}

// Define animal of type CAnimal.
var animal : CAnimal;

animal = new CDog;
// animal uses printQualities from CDog.
animal.printQualities();

animal = new CKangaroo;
// animal uses printQualities from CKangaroo.
animal.printQualities();

The output of this program is:

A dog has four legs.
A kangaroo has a pouch.

Requirements

Version .NET

See Also

Modifiers | final Modifier | static Modifier | var Statement | function Statement | class Statement | Variable Scope | new Operator

Show:
© 2014 Microsoft