Static Class and Class Member, static class member

Source: Internet
Author: User

Static Class and Class Member, static class member

1. Static classes only contain static members

2. Unable to instantiate

3. It is sealed and cannot be inherited

4. There can be a static constructor that cannot contain the instance constructor.

5. Access static members directly with class names and members

6. A common use of static classes may be to create a mathematical library containing a set of mathematical methods.

Public static class MyMath {public static float PI = 3.14f; public static bool IsOdd (int x) {return x % 2 = 1 ;}}

 

 

A. Non-static classes can contain static methods, fields, attributes, or events.

B. Static methods and attributes cannot access non-static fields and events.

C. The const field is static in nature.

Public class Automobile {private static int Val; private const int NumberOfWheels = 4; // const handles public static void Print () {Console. writeLine ("The automobile have {0} wheels. ", NumberOfWheels);} public static int Size // only static fields can be accessed {get {return Val;} set {Val = value ;}}}

 

Related Article

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.