Abstract classes include abstract methods and non-abstract methods. Abstract classes cannot be instantiated.
A sealed class prevents inheritance and cannot be used as a base class.
To declare an abstract class, you need to put the keyword abstract before the class definition. An example of a class member in an abstract class is as follows, where an abstract method is defined -
public abstract class Vehicle { public abstract void display(); }
The abstract method definition is followed by a semicolon because it is not implemented.
To declare a sealed class, you need to place the keyword seal class definition in front. A sealed class prevents inheritance, and you cannot use it as a base class.
public sealed class Test { // Class members comes here }
The above is the detailed content of Abstract classes, sealed classes and class members in C#. For more information, please follow other related articles on the PHP Chinese website!