What are the advantages of non-static class over static class?
static class need not be instanciated. so we can directly use ClassName.MemberName
, so then whats the use of nonstatic class
Difference between static and non-static classStatic class is defined using static keyword. Non-Static class is not defined by using static keyword. In static class, you are not allowed to create objects. In non-static class, you are allowed to create objects using new keyword.
A static variable acts as a global variable and is shared among all the objects of the class. A non-static variables are specific to instance object in which they are created. Static variables occupies less space and memory allocation happens once. A non-static variable may occupy more space.
A static class means you reuse the same elements without needing to deal with instantiating the same things over and over. Non-static classes allow for data to be different but the operations to be the same.
A static class is similar to a class that is both abstract and sealed. The difference between a static class and a non-static class is that a static class cannot be instantiated or inherited and that all of the members of the class are static in nature.
A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself
A static class has only one instance of the class itself so you cannot create multiple instance of a static class.
looking at your question you cannot set two different values to the below property if the class is static because there will be only one instance of ClassName
in memory
ClassName.MemberName
more info at
http://msdn.microsoft.com/en-us/library/79b3xss3.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With