Can we have private constructor in our class file. When we
are trying to create instance for the class will it create
or throw error regarding that?
Answer Posted / nevin jain
yes off-course instance can be created...
just make a static function say ReturnInstance() within the
class n keep return type of this function as the name of the
class..
with in ReturnInstance() method return the object of the class..
As the method is static so it will load without using
instance n now we can assign the object(or instance)to the
variable of class type...
examine:
public class A
{
private A()
Console.Writeline("Instance is created");
public static A ReturnInstance()
{
return new A();
}
public void Display()
{
Console.WriteLine("Display is accessed");
}
}
class MyMain
{
public static void main()
{
A a=A.ReturnInstance();
a.Display();
}
}
Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What is ac callback?
What is method and function in c#?
What is difference between array and collection in c#?
What happens if a static constructor throws an exception?
Is dictionary reference type c#?
How does bitwise xor work?
List the two important objects of ado.net and also list the namespaces that are commonly used in ado.net to aid in connection to a database.
How can I develop an application that automatically updates itself from the web?
Can we extend sealed class in c#?
Why it's said that writing into .NET Application Configuration Files is a Bad Idea?
Can abstract class have private constructor c#?
What's the difference between class and object?
What is the implicit name of the parameter that gets passed into the class set method?
what is IDisposal interface
These questions were asked me in a technical interview: •If we deploy an application on multiple server (like database server, web server) then, each request should be redirected to proper server, then how you will handle it in your code? •How security pinholes will be handled in an application? •What things should be considered while writing a web application? •How will you do load/performance testing of web application? Which framework you will use for it? •How will you implement a cache for results which require a DB access? Please let me know how to write an web application considering all these points. I am not so much aware of architechural design of web application. Your guidelines will be helpful.