You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `abstract` modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the `abstract` modifier in a class declaration to indicate that a class is intended only to be a base class of other classes, not instantiated on its own. Members marked as abstract must be implemented by non-abstract classes that derive from the abstract class.
15
+
16
+
Abstract classes can contain both abstract members (which have no implementation and must be overridden in derived classes) and fully implemented members (such as regular methods, properties, and constructors). This allows abstract classes to provide common functionality while still requiring derived classes to implement specific abstract members.
15
17
16
-
## Example 1
18
+
## Example 1 - Abstract class with mixed members
19
+
20
+
The following example demonstrates an abstract class that contains both implemented methods and abstract members:
In this example, the `Vehicle` abstract class provides:
25
+
26
+
-**Implemented members**: `GetInfo()` method, `StartEngine()` method, and constructor - these provide common functionality for all vehicles.
27
+
-**Abstract members**: `Move()` method and `MaxSpeed` property - these must be implemented by each specific vehicle type.
28
+
29
+
This design allows the abstract class to provide shared functionality while ensuring that derived classes implement vehicle-specific behavior.
30
+
31
+
## Example 2
17
32
18
33
In this example, the class `Square` must provide an implementation of `GetArea` because it derives from `Shape`:
19
34
@@ -25,6 +40,8 @@ The `abstract` modifier indicates that the thing being modified has a missing or
25
40
26
41
- An abstract class may contain abstract methods and accessors.
27
42
43
+
- An abstract class can also contain implemented methods, properties, fields, and other members that provide functionality to derived classes.
44
+
28
45
- It is not possible to modify an abstract class with the [sealed](./sealed.md) modifier because the two modifiers have opposite meanings. The `sealed` modifier prevents a class from being inherited and the `abstract` modifier requires a class to be inherited.
29
46
30
47
- A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.
@@ -61,7 +78,7 @@ The `abstract` modifier indicates that the thing being modified has a missing or
0 commit comments