What is a private constructor? where will you use it?
Answer Posted / 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 |
Post New Answer View All Answers
Do we get an error while executing the “finally” block in c#?
What is the difference between struct and class c#?
How Do You Convert A Value-type To A Reference-type?
What is readline library?
Can a class or a struct have multiple constructors?
Explain code compilation in c#.
Explain the accessibility modifier protected internal?
What is lock statement in C#?
Explain about multithreading?
What do you mean by shared assembly?
Do vs while c#?
write a C# Program add two matrix ?
Why do we use methods in c#?
What is extended class in c#?
How do you declare a method in c#?