Can we create constructor for static class?

 Posted by Rajni.Shekhar on 4/9/2012 | Category: C# Interview questions | Views: 3444 | Points: 40
Answer:

No, we can not create constructor for static class, as it its member are called by class name itself.

Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Class1
/// </summary>
public static class Class1
{
private Class1() //Error: Static classes cannot have instance constructors
{
//
// TODO: Add constructor logic here
//
}
}

even static class will have only static members.


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response