C # static class test you

Source: Internet
Author: User

Questions, which are described below which are correct and which errors

  1. Static classes must derive directly from the base class System.Object
  2. Static classes cannot implement any interface
  3. Static classes can only define static members (fields, methods, properties, and events)
  4. A static class cannot be used as a field, a method parameter, or a local variable
  5. Static classes cannot inherit static classes
  6. Static classes cannot be applied to structs (value types)
  7. Static classes often store extension methods
  8. If the programming language does not support the definition of a static class, define the class as abstract,sealed and define the class's instance constructor as private
  9. Static method calls do not need to instantiate a static class and call the method directly using the type name

Answer:

  1. Correctly, inheritance applies only to objects, and you cannot create instances of static classes.
  2. Correct, because the class's interface method can be called only when an instance of the class is used.
  3. Correctly, any instance member compiler in the static class will make an error.
  4. Correct, because they represent the variables of the instance.
  5. Correct, because static classes are marked abstract and sealed
  6. Correct, because structs (value types) are instantiated
  7. Correctly, static classes are widely used to provide shortcuts to access other operations, to store extension methods, or to extract features in a non-object-oriented manner (such as system.enviroment)
  8. Correct, for example. net1.0 does not support static classes, so processing, instance constructors defined as private cannot construct an instance
  9. Correct, static classes do not need to be instantiated, calling methods directly using the class name

Bibliography:

CLR via C # (fourth edition)

NET design specification conventions, idioms and Patterns (second edition)

C # static class test you

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.