Static
Class:
- A static class cannot be instantiated
- Only contains static members (property/methods/fields)
- Static class cannot implement an interface
- Static class cannot have any instance members (property/methods)
- Static class can’t declare any constructors and the compiler doesn’t create a parameter-less constructor by default
- Static class are implicitly abstract, you can’t add the abstract modifier yourself
- Static class may be generic
- Static class may be nested, in either non-static or static class
- Static class may have nested types, either non-static or static
- Only static, top-level non-generic class can contain extension methods (3.0)
- A static class is never instantiated
- static keyword on a class enforces that a type not be created with a constructor
- A static constructor initializes static fields before accessing
Static Method:
- Cannot access non-static class level members (property/method)
- Static methods can be public or private
- Static methods are by default private
- Static properties are similar to static methods
- Static methods have no way of accessing fields that are instance fields however instance methods can access static fields
- Static method can access non-static fields only by passing instance fields as parameters using its non-static class’s object in which static method is available
- Static method can have only non-static parameters
- Any type of method(static/non-static) cannot have static members
No comments:
Post a Comment