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...


What is a private constructor? where will you use it?

Answers were Sorted based on User's Feedback



What is a private constructor? where will you use it?..

Answer / ramkishore mateti

When you declare a Constructor with Private access modifier
then it is called Private Constructor.

If you declare a Constructor as private then it don't allow
to create object for its derived class,i.e you loose
inhirect facility for that class.
Ex:
Class A
{
// some code
Private Void A()
{
//Private Constructor
}
}

Class B:A
{
//code
}

B obj = new B();// will give Compilation Error

Because Class A construcor declared as private hence its
accessbility limit is to that class only ,Class B can't
access. As i explained the heirarchy of Constructors in the
previous qn, when we create a object for Class B that
constructor will call constructor A but class B have no
rights to access the Class A constructor hence we will get
compilation error.

Is This Answer Correct ?    29 Yes 1 No

What is a private constructor? where will you use it?..

Answer / nitesh

When we want to control the object instantiation
or trying to implement singleton pattern

Is This Answer Correct ?    10 Yes 2 No

What is a private constructor? where will you use it?..

Answer / dsr

private constructor access only that class. we can't access
in other class.we can use the private constructor in
singleton patteren.

Is This Answer Correct ?    5 Yes 0 No

What is a private constructor? where will you use it?..

Answer / nevin jain

In singleton pattern we make the class sealed n keep
contractor as protected
......which is same as keeping class with any access
modifier with private constructor..

both pattern is the example of singleton pattern..
basically this pattern say that only single instance can be
created of the class which can be achieved either by private
constructor or sealed class with protected constructor..

Is This Answer Correct ?    3 Yes 0 No

What is a private constructor? where will you use it?..

Answer / saurabh

In singleton pattern the constructor is not private but
protected.

Go for private constructor when your class has methods which
do not require object creation. ex. (Math class in c#).
Like If your class has all static method, you need not to
create an object in that case go for private constructor.

Is This Answer Correct ?    2 Yes 1 No

What is a private constructor? where will you use it?..

Answer / sri

we can declare the constructor private ,it is called
private constructor.

Is This Answer Correct ?    3 Yes 15 No

Post New Answer

More C Sharp Interview Questions

What’s thread.sleep() in threading ?

0 Answers  


Explain get and set accessor properties?

0 Answers  


Why are local variables stored in stack?

0 Answers  


How do I create a dbml file?

0 Answers  


What are collection classes?

0 Answers  


What?s the difference between an interface and abstract class?

4 Answers  


How do you escape c#?

0 Answers  


Are enums static c#?

0 Answers  


How do you encapsulate in c#?

0 Answers  


C Sharp

1 Answers   Wipro,


Hello Friends..am Mohammed riyash..final year BCA in Jamal Mohamed College 2009. Trichy. My doubt is while connecting SQL2005 Built in Database withing the Visual Studio 2005 Framework.. I am getting the error.. That " An Error occurred and it may be due to , under the default settings of the Server, the connection cannot be established.." But the code works in MS Access for me.. Both in VB.Net and C#.Net am getting the same error.. Any genius please Message me to 9994558822 or mail me.. riyash.ips@gmail.com

3 Answers  


What is a function c#?

0 Answers  


Categories