.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Interview Question >> OOPS >> Post New Question Subscribe to Interview Questions

Whether we can create a private constructor for a class?

Posted By :nishithraj     Posted Date :December 31, 2009    Points :10   Category :OOPS 
Yes it is possible. we can create a private constructor for a class

You can also find related Interview Question to Whether we can create a private constructor for a class?  below: 

What is Private Constructor? and it's use? Can you create instance of a class which has Private Constructor?

When a class declares only private instance constructors, it is not possible for classes outside the program to derive from the class or to directly create instances of it. (Except Nested classes)
Make a constructor private if:

1) You want it to be available only to the class itself. For example, you might have a special constructor used only in the implementation of your class' Clone method.

2) You do not want instances of your component to be created. For example, you may have a class containing nothing but Shared utility functions, and no instance data. Creating instances of the class would waste memory. (More...)

How Many Constructor we can create in side the class.

we can create more constructor inside the class (More...)

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

When you declare a Constructor with Private access modifier then it is called Private Constructor. We can use the private constructor in singleton pattern.

If you declare a Constructor as private then it doesn't allow to create object for its derived class, i.e you loose inherent facility for that class. (More...)

Are private class-level variables inherited?

Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. (More...)

Are private class-level variables inherited?

Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are. (More...)

A constructor can be private. True or False

False. A constructor should not be private. (More...)

Where we can use the private constructor?

A private constructor is a special instance constructor. It is commonly used in classes that contain static members only. (More...)

Which design pattern should have private or protected constructor?

singleton design pattern should have private or protected constructor (More...)

Can namespace contain the private class?

no, having a single private class does not mean anything , it is applicable only in case of nested class.

How can you access a private method of a class?

Use .Net Reflection. Using reflection we can invoke private methods too.


Car car = new Car();
Type type = car.GetType();
MethodInfo methodInfo = type.GetMethod("ShiftGearUp", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo.Invoke(car, null);

Pre: Create a class Car with private method "ShiftGearUp" (More...)

What is the use of private constructor in Java?

A private constructor is used when there is no requirement of another class to invoke that. It is used mostly in implementing singletons. A static method is used for managing the creating the instances of that class.

The following is the example of private constructor.

public class Singleton {
private static Singleton instance;.
//private constructor
private Singleton {
// some code goes here
} (More...)

In which order the constructor is called for an inherited class?

Constructor of Parent class is called


Constructor of Child class (More...)

Are private class-level variables inherited?

Yes,private class members are inheritable, but they are not accessible (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend