Wednesday 23 March 2011

Static Keyword related Questions

What is a Static class? What are its features?

Static class is a class which can be accessed without creating an instance of the class.
Important Features:
a. Static class only contains static members.
b. Static class need not to be instantiated.
c. Static classes are sealed by default and therefore cannot be inherited.

What is sealed class? What are its features?

Sealed classes are those classes which can not be inherited and thus any sealed class member can not be derived in any other class.
A sealed class cannot also be an abstract class.
In C# structs are implicitly sealed; therefore, they cannot be inherited.

What is a life span of a static variable?

A static variable’s life span is till the class is in memory.

Why main function is static?
To ensure there is only one entry point to the application.

What is static member?

static members are the members that can be called directly from the class name, it doesnt require the object of the class.

What is static constructor?

When constructors are used to set the value of a type’s data at the time of construction, if we want the value of such static
data is to be preserved regardless of how many objects of the type are created, we have to define the constructor with static keyword.


Can you declare the override method static while the original method is non-static?

No, you can’t, the signature of the virtual method must remain the same, only the keyword virtual is changed to keyword override.

No comments:

Post a Comment