Declarations of classes in C #

Source: Internet
Author: User
Tags inheritance modifier modifiers

The declaration format for a class is as follows:

Attributes Class-modifiers class identifier Class-base class-body;

Where attributes, Class-modifiers, Class-base, and class-body are optional. Attributes is the property set, Class-modifiers is the modifier of the class, and the keyword class follows the name Indentifier,class-base and Class-body of the class to represent the inheritance and the base class name.

Modifier for Class

The modifiers of a class can be one or both of the following (the same modifier is not allowed to appear multiple times in the declaration of a Class):

The new---only allows for use in nested class declarations, indicating that the class hides members that are inherited from the base class and that have the same name as the base class.

The public---means that access to the class is not restricted.

Internal---Only the class in which it resides.

Private---only on packages. NET to access the application or library in.

Abstract---Abstraction class, which does not allow instances of classes to be established.

Sealed---Sealed class and is not allowed to be inherited.

Using instances of a class

Use the new keyword to create an instance of a class, such as the following code:

Class a{}
class b{
   void f{
       a a=new a ();
   }

An instance of Class A is created in method F of Class B.

Inheritance declarations for classes

We use the following code to indicate that Class B inherits from Class A:

Class a{}

Class b:a{}

For the inheritance mechanism in C # we will discuss in detail in part fourth, where it is stated that the classes in C # support only single inheritance.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.