Friday 12 July 2013

OOPS CONCEPT



Inheritance Types
Single Level
Multil Level
Multiple
Hierachical
Hybrid


Constructor Definition:
 Constructor is method in the class which is having Class name. When we create an instance of the class this method will call.. 
Types of Constructors: Mainly C# Supports five types of constructors in the C#.net 

 
Types of Constructors  
Default Constructor.
Parameterized Constructor.
Copy Constructor.
Static Constructor.
Private Constructor.
 

Static Constructor and normal Constructor  
Most of the people are getting getting lots of confusion on Static Constructors. Today i want write my views on static constructors in .net.   
Can we declard constructor as Static?
Yes.

 Can we declare Constructor as Private?
Yes.
 
What are differences between Normal and Static Constructors in .net?

Normal Constructors:

1. Used for initialize class variables.
2. Normal constructors are instance level.
3. For every time of object initialization constructor will call.

Static Constructors:
1. Used for initialize class level static variables.
2. Static constructors can't accept any other objects other than static like static methods. If we write also compile time errors will come. like "An object reference is required for the non-static field, method, or property 'ConsoleApplication1.staticClass.strName'ConsoleApplication1\StaticConstructor.cs"
3. These are very similar to static methods, like static constructors are class level not instance level.
4. Static constructors are called only once.
5. Static constructors will not take any kind of access modifiers like private, public, internal ...


Static constructor have Access Specifiers or not?
No, static constructors shouldn't have access specifiers. Those are strictly private.

Can static constructors have arguments ?
static constructors don't take any arguments.

What is the level of access for Static constructor, if class will public?
This time also private only like normal constructor.

When we will use static constructor, what is the use of that?
Based on requirement like whenever we want to initialize static variables. which needs to be execute once, that time we will use this static constructor.

No comments:

Post a Comment