abstract classes
Abstract classes and members are incomplete and must be implemented in a derived class.
- They cannot be directly instantiated.
- They cannot be static.
- They may contain constructors.
Abstract, Concrete, Virtual, and Static Members
Abstract classes may contain abstract, concrete, virtual, and static members:
abstractmembers have no implementation.- They must be implemented in the derived class. Use the
overridekeyword. - A field cannot be abstract.
- They cannot be static.
- They must be implemented in the derived class. Use the
- Concrete members have an implementation. They are inherited in the derived class like normal.
- They may be re-implemented in the derived class with the
newkeyword. - They may be static.
- They may be re-implemented in the derived class with the
virtualmembers have an implementation. They are inherited in the derived class like normal.- They may be re-implemented in the derived class with the
overridekeyword. - They cannot be static.
- They may be re-implemented in the derived class with the
staticmembers have an implementation.- They may be re-implemented in the derived class with the
newkeyword.
- They may be re-implemented in the derived class with the
| Member Modifier | Default Implementation | Re-implement | Keyword | Static |
|---|---|---|---|---|
| abstract | No | Must | override | No |
| virtual | Yes | May | override | No |
| (concrete) | Yes | May | new | May |
| static | Yes | May | new | Yes |
sealed
The sealed keyword prevents inheritance of a class, or of class members that were previously marked virtual.
Because a sealed class cannot be the base class of a derived class, it also cannot be abstract.