Interview Part 1-Static class are almost same as default non-static class ,but there is difference:
Static
Static
- Static class is defined using static keyword.
- In static class, you are not allowed to create objects.
- The data members of static class can be directly accessed by its class name.
- A static class members are accessed by the class name followed by the member name.
- It is allowed to have only static members,
- Static class cannot inherit from another class (it's sealed).
- static classes are marked as
sealed
andabstract
by compiler in the output MSIL. - A static constructor in a static class runs only once when any of its static members accessed for the first time.
- Static members are allocated in high frequency heap area of the memory.
- Static cannot be used with indexers, destructors or types other than classes.
Non-Static
- Non-Static class is not defined by using static keyword.
- In non-static class, you are allowed to create objects using new keyword.
- The data members of non-static class is not directly accessed by its class name.
- Non-static class may contain both static and non-static methods.
- Non-static class contains an instance constructor.
- Non-static class can be inherited from another class.
if you need more Static & Non-Static