Questions, which are described below which are correct and which errors
- Static classes must derive directly from the base class System.Object
- Static classes cannot implement any interface
- Static classes can only define static members (fields, methods, properties, and events)
- A static class cannot be used as a field, a method parameter, or a local variable
- Static classes cannot inherit static classes
- Static classes cannot be applied to structs (value types)
- Static classes often store extension methods
- 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
- Static method calls do not need to instantiate a static class and call the method directly using the type name
Answer:
- Correctly, inheritance applies only to objects, and you cannot create instances of static classes.
- Correct, because the class's interface method can be called only when an instance of the class is used.
- Correctly, any instance member compiler in the static class will make an error.
- Correct, because they represent the variables of the instance.
- Correct, because static classes are marked abstract and sealed
- Correct, because structs (value types) are instantiated
- 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)
- Correct, for example. net1.0 does not support static classes, so processing, instance constructors defined as private cannot construct an instance
- 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