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 is sendredirect?
What is difference between printf and scanf?
Why we cannot override static method?
Hi Friends, I am beginner in java. what i know about synchonized keyword is,If more that one 1 thread tries to access a particular resource we can lock the method using synchronized keyword. Then after that how the lock is released and how next thread access that.Please explain with example.
How to count occurrences of each duplicate element in a list {a,b,d,c,a,b} ? Thanks in Advance
java program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.
Are primitives objects?
what is check p object in java
What modifiers may be used with an inner class that is a member of an outer class in java programming?
Is it possible to use string in the switch case?
Can arraylist hold different types java?
Can we make constructors static?