Abstract classes, sealed classes and class members in C#

王林
Release: 2023-09-14 22:21:06
forward
769 people have browsed it

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 aclass memberin an abstract class is as follows, where an abstract method is defined -

public abstract class Vehicle { public abstract void display(); }
Copy after login

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 }
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!