what is the use of declaring constructor as private?
Answers were Sorted based on User's Feedback
Answer / ranganathkini
By declaring the class constructor as private, other classes
cannot create instances of the class.
This design is usually used in singleton patterns.
| Is This Answer Correct ? | 22 Yes | 2 No |
Answer / ranganathkini
By making all the constructors of a class private, you can
also prevent other class from extending the class without
marking the class final.
| Is This Answer Correct ? | 9 Yes | 6 No |
Answer / suganya
prevent to access by other class even sub class cant have
permission to create object of that base class.
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / ravikiran
In order to restrict the class to get subclassed
| Is This Answer Correct ? | 6 Yes | 6 No |
Answer / anshul
A private constructor is a special instance constructor. It is commonly used in classes that contain static members only. If a class has one or more private constructors and no public constructors, then other classes (except nested classes) are not allowed to create instances of this class.
| Is This Answer Correct ? | 0 Yes | 1 No |
how to create multithreaded program? : Java thread
What is the difference between iterator and list iterator?
What is scope & storage allocation of global and extern variables? Explain with an example
how can we import the user defined package without classpath?
What is constructor and its types?
What is difference between local variable and global variable?
How do you access command-line arguments within the code?
0 Answers Flextronics, Hexaware,
What is a numeric format?
what is the use of datasource in core java?
what is the difference between cd & dvd ?
30 Answers Lovely Professional University, Satyam, Sibylsys,
Does java return by reference?
What is exception hierarchy in java?