Answered On : Jan 3rd, 2006
True
Answered On : Jan 4th, 2006
I think Answer is True.A class can have static constructor, the static constructor would only be executed when the first time the class is instanciated. not with every time a instance is created, a pulic constructor would be executed every time when the class is instantiated including the first time when static constructor is instanciated.Hari
The Ans is False. Guys, the author statement says "We can't have static constructors" which is false becoz we can have static constructors.
Answered On : Jan 9th, 2006
True Constructor can NOT be static.
True, constructor cannot be static.
Answered On : Jan 31st, 2006
False, constructor can be declared static.
C# supports two types of constructor, a class constructor (static constructor) and an instance constructor (non-static constructor).
Static constructor is used to initialize static data members as soon as the class is referenced
first time, whereas an instance constructor is used to create an instance of that class with
Since static constructor is a class constructor, they are guaranteed to be called as soon as we refer to that class or by creating an instance of that class.
Answered On : Jan 31st, 2006
FalseAuthor trying to make us fool.This is a puzzling question.Author wants to know our presence of mind.As Mr. Naveen Said that author question is "Constructors can not be static" but constructors can be static.So ans is False
False, for sure, constructors can be declare static
Answered On : Mar 28th, 2006
Answer is Fasle.
You can have static constructor in a class very well..By having static constructor it gets invoked before any instance variables declared in a class
Answered On : Mar 29th, 2006
* constructors can be static * a static constructor must be parameterless * static constructors will be executed before other constructors * constructors can have access modifiers (but static constructors CAN NOT) /*Sample*/ using
namespace
ConsoleApplication2{
class Class1{
static Class1(){
Console.WriteLine("static Class1()");
}
public Class1(){
Console.WriteLine("Class1()");
}
private Class1(string abc){
Console.WriteLine("private Class1(string abc)");
}
[STAThread]
static void Main(string[] args){
//***** Return static Class1, then Class1 //Class1 myclass = new Class1(); //Console.ReadLine(); //***** Return static Class1, then private Class1Class1 myclass =
new Class1("test");Console.ReadLine();
}
}
}
Answered On : Apr 20th, 2006
B is the correct answer. We have the concept of static constructor. A static constructor
* is parameterless constructor.
* has no access modifier associated with it. it would be a compile time error otherwise.
* is executed before the class (that have static constructor) object is instantiated and executed only once i.e. at the time of first object instatiation.
* can not be accessed directly as instance constructors.
* can access only static members of the class.
There can be only one static constructor in the class, as static constructor is declared as
public class ClassA
{
static ClassA() // simple signature--no access modifier/no parameter
{
}
}
so there is no way to declare another static constructor. (Concept of Method Overloading)
Moreover, Static constructor is called by the CLR(the runtime-execution environment of .NET), and not by the object, so there is no need of access modifier and parameters to static constructors.
Answered On : Jul 17th, 2006
hi
Contructor can be static and it can be private also
Answered On : Aug 31st, 2006
access modifiers are not allowed on static constructors
constructors can be static. this will clarify doubts about static constructors
http://www.c-sharpcorner.com/UploadFile/cupadhyay/StaticConstructors11092005061428AM/StaticConstructors.aspx
Answered On : May 9th, 2008
View all questions by ushalakshmi View all answers by ushalakshmi
Answer is False
We have a Static constructors......
It is a special type of constructor, introduced with C#. It gets called before the creation of the first object of a class(probably at the time of loading an assembly).
Example:
public class SomeClass()
{
static SomeClass()
{
//Static members may be accessed from here
//Code for Initialization
}
}
False.
Constructors can be static only for static members of class
False:
One novel feature of C# is that it is also possible to write a static no - parameter constructor for a class.
Such a constructor will be executed only once, as opposed to the constructors written so far, which are instance constructors that are executed whenever an object of that class is created.
One reason for writing a static constructor is if your class has some static fields or properties that need to be initialized from an external source before the class is first used.
Constructors can be static.
Constructors can be static
constructor can be static.static constructors are used to initialized static datafields.static constructors doesn't have return type.static constructor can be invoked when first object creation of the class from the second object onwards it doesn't call the static constructor.
false
False. Constructors can be declared as Static.
There is static cunstructor for static class
It is false. using System.Collections.Generic; using System.Linq; using System.Text; { class Program { class FOO { int ns = 0; { s=s+1; } { s = s + 1; } { } { } } { } } }
If it is static, it can only constructed one time. See the following example.
using System;
The output is ---
Static 1
Public 2
Public 3
Press any key to continue . . .
In C# . Net Constructors can be static. There are five constructor in C# . Net.
1. Default constructors or Non-parameterized constructor
2. Parametrize constructor
3. Static constructor
4. Private constructor
5. Copy constructor.
Static constructor is the only constructor which doesn't construct the instance type.
In c# static constructor available.
if we have different constructor in the class. static constructor execute first , after that only other constructor will execute
Its possible in C#. Tommy has answered perfectly...
The answer is False.
Constructors CAN BE declared as static . Another thing to keep in mind is that you cannot use access modifiers with static constructors as you can do with static methods.
For Ex :
public static Class1() // INVALID STATEMENT
{
}
public static string getString() // VALID STATEMENT
{
return "";
}
Constructors can be static.
Static constructors are used to initialize static members. Static constructors has following properties:
1) It can not have access modifier and parameters
2) It get executed when a class is instantiated or referenced static member is called.
It's "False" , static constructors are used to initialize the static variables of a class.....
Code
//Example public class Class1 { static int number1; int number2; static Class1() { number1=10; } }
Answered On : Sep 23rd, 2011
False.
There are three constructors .Static,Private and Public Constructors.
No, Constructors can be Static...
http://msdn.microsoft.com/en-us/library/k9x6w0hc(v=vs.80).aspx
Incorrect
true
Constructors can be static in c#
False, constructor can be declared static.
C# supports two types of constructor, a class constructor (static constructor) and an instance constructor (non-static constructor).
but if constructor is static then they can access only static members
Answered On : Mar 2nd, 2012
A class can have only one static constructor.
Static constructor can not have any parameter.
Static constructor cannot have any access specifier, not even private.
It is used to initialize the static data members of the class.
For any number of object creation, the static constructor gets executed only once.
The static constructor gets executed when the class is used or referenced for the very first time in the application.
Static constructor can not be invoked by the programmer explicitly.
Yes, there can be a static constructor. It will be at class level & executed just once. It is totally in run-times control & not sure of when this will be executed. But, it is assured that it will be executed before creating instance of the class.
Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.
