Question of the day :Day 6





Question of the day.

Question:

What is a Static class and Why do wee need it?

Answer:


The Word Static means unchangeable or not moving or fixed.So a static class means whose value is fixed in the Memory.Static classes are light weight and don’t need instantiation.It is not possible to create instances of a static class using the new keyword.A static class cannot have non-static members.Static classes are loaded automatically by the .NET Framework common language runtime (CLR) when the program or namespace containing the class is loaded.



The advantage of using a static class is that the compiler can check to make sure that no instance members are accidentally added. The compiler will guarantee that instances of this class cannot be created. thus you can say that Static Class is an Example of Data Hiding.



Static classes are sealed and therefore cannot be inherited.



When you want to restrict the class from creating any objects of its we can go for a static class

HappyCoding ! 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: