Home  >  Article  >  Backend Development  >  Abstract classes, sealed classes and class members in C#

Abstract classes, sealed classes and class members in C#

王林
王林forward
2023-09-14 22:21:06776browse

C# 中的抽象类、密封类与类成员

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.

Abstract 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.

Sealed class

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete