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 |
What if the main() method is declared as private? What happens when the static modifier is removed from the signature of the main() method?
What exactly is methodology?
Can we override the private methods?
Where is singleton pattern used?
FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?
What is sortedmap interface?
What is default size of arraylist in java?
What are the different approaches to implement a function to generate a random number?
0 Answers Axtria, ITC Indian Tobacco Company,
How do you sort a list in java?
What is the difference between final, finally and finalize() in java?
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
What is the java project architecture?