Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Where is the keyword void used?

937


What are the benefits of using generics in c#?

905


Explain about Serialize and MarshalByRef?

955


Where test director stores its data ? Database ,Local file etc...? I need to read this data from Visual Studio 2005 c# client. Regards

1859


What is an int in c#?

905


Explain about Error handling and how this is done

941


What is exe file in c#?

877


what is the difference between a struct and a class in c#?

1142


Why delegates are safe in c#?

873


Why are dynamic link library used over static one?

967


What is a protected class c#?

887


What are constants in c#?

960


What is the difference between protected and internal in c#?

1009


What is an arraylist in c#?

1077


Can a class or a struct have multiple constructors?

961