Information Technology Reference
In-Depth Information
Abstract Members
An abstract member is a function member that is designed to be overridden. An abstract mem-
ber has the following characteristics:
It is marked with the abstract modifier.
￿
￿
It does not have an implementation code block. The code blocks of abstract members
are replaced with semicolons.
For example, the following code from inside a class declaration declares two abstract
members—an abstract method called PrintStuff and an abstract property called MyProperty .
Notice the semicolons in place of the implementation blocks.
Keyword Semicolon in place of implementation
abstract public void PrintStuff(string s);
abstract public int MyProperty
{
get; Semicolon in place of implementation
set; Semicolon in place of implementation
}
Other important facts about abstract members are the following:
￿
Abstract methods, although they must be overridden by a corresponding method in a
derived class, cannot use the virtual modifier in addition to the abstract modifier.
￿
As with virtual methods, the implementation of an abstract method in a derived class
must specify the override modifier.
￿
Abstract members can be declared only in abstract classes , which you will look at in the
next section.
Table 7-3 compares and contrasts virtual members and abstract members.
Table 7-3. Comparing Virtual and Abstract Members
Virtual Member
Abstract Member
virtual
abstract
Keyword
Implementation body
Has an implementation body
No implementation body—
semicolon instead
Overridden in a derived class
Can be overridden—using
override
Must be overridden—using
override
Types of members
Methods
Properties
Events
Indexers
Methods
Properties
Events
Indexers
Search WWH ::




Custom Search