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
What is static void main in c#?
When should I use static in C#?
What is a multicast c# delegate?
How long does it take to learn c# for unity?
Write a program to create a user control with name and surname as data members and login as method and also the code to call it. (Hint use event delegates) Practical Example of Passing an Events to delegates
Why do we need delegates?
What is dependency injection in simple words?
What is the difference between method overriding and method overloading?
what are the different ways a method can be overloaded?
What is oledb in c#?
How do you inherit a class into other class in c#?
Explane each and every methods of nterface Queue? Explain About performance issues on retrieving records
What is disco?
what is the meaning of Object lifetime in OOPS
What is uint64_t?