0

I want to know how are static class Instantiated. I mean according to OOPS concepts no class can be used without instantiating it. But still we can use static classes without instantiating it, so when and how does static classes get instantiated.

Edited-------

Also I am confuse about the constructor calls when I am inheriting an abstract class and I make a instance of child class. can anyone explain me that also.

Thanks in Advance.

Sumit
  • 2,932
  • 6
  • 32
  • 54
  • Any particular language/framework? – Rowland Shaw May 06 '11 at 08:56
  • @rowland: you can take C# as an reference to explain me the concept. – Sumit May 06 '11 at 09:13
  • 1
    @unapersson : "static classes" are very commonly used, I am surprised that you havent heard of static class. I am taking C#(.NET) as reference, I dont know if static class are known by different name in other languages/framework – Sumit May 06 '11 at 09:13
  • @unapersson static classes are *required* fro extension methods in the .Net world; The `Console` class is typically static in most OOP languages that have it (or something like it) – Rowland Shaw May 06 '11 at 09:29
  • @Rowland Well, certainly C++ doesn't, unless by static class you mean one that only contains static data and function members. In which case, it is an example of the "monostate" pattern. –  May 06 '11 at 09:38

1 Answers1

1

The mechanism will vary from framework to framework, but in the .Net world, the static constructor is called when the type is initialised -- it is key to remember that the developer has no direct control over when the constructor is called, so it would be dangerous to rely on a particular implementation in a particular version of the framework.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
  • thanks and can you please check edited question, I want to know about abstract classes also.\ – Sumit May 06 '11 at 09:43
  • @Sumit that's a different question, and requires further detail (e.g. are explicit constructors involved, you are you only interested in compiler supplied constructors, etc.) - you would be better to ask it as a separate question, assuming that answers to questions like http://stackoverflow.com/q/1882692/50447 don't already answer it for you. – Rowland Shaw May 06 '11 at 09:53
  • hmmm, ok then i'll put up an different question for that. – Sumit May 06 '11 at 10:00