다음을 통해 공유


Classes

If you are familiar with object-oriented programming, you know that a class defines the operations an object can perform (methods, events, or properties) and defines a value that holds the state of the object (fields). Although a class generally includes both definition and implementation, it can have one or more members that have no implementation.

An instance of a class is an object. You access an object's functionality by calling its methods and accessing its properties, events, and fields.

The following table provides a description of some of the characteristics that the runtime allows a class to have. (Additional characteristics that are available through Attribute classes are not included in this list.) Your language might not make all these characteristics available.

Characteristic Description
sealed Specifies that another type cannot be derived from this type.
implements Indicates that the class uses one or more interfaces by providing implementations of interface members.
abstract Specifies that you cannot create an instance of the class. To use it, you must derive another class from it.
inherits Indicates that instances of the class can be used anywhere the base class is specified. A derived class that inherits from a base class can use the implementation of any virtual methods provided by the base class, or the derived class can override them with its own implementation.
exported or not exported Indicates whether a class is visible outside the assembly in which it is defined. Applies only to top-level classes.

Nested classes also have member characteristics. For more information, see Type Members.

Class members that have no implementation are abstract members. A class that has one or more abstract members is itself abstract; new instances of it cannot be created. Some languages that target the runtime allow you to mark a class as abstract even if none of its members are abstract. You can use an abstract class when you need to encapsulate a basic set of functionality that derived classes can inherit or override when appropriate. Classes that are not abstract are referred to as concrete classes.

A class can implement any number of interfaces, but it can inherit from only one base class. All classes must have at least one constructor, which initializes new instances of the class.

Each language that supports the runtime provides a way to indicate that a class or class member has specific characteristics. When you use the syntax required by your language, the language ensures that the characteristics of the class and its members are stored (as metadata) along with the implementation of the class.

See Also

Common Type System | Interfaces | System.Object | Metadata