what is the use of declaring constructor as private?

Answers were Sorted based on User's Feedback



what is the use of declaring constructor as private?..

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

what is the use of declaring constructor as private?..

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

what is the use of declaring constructor as private?..

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

what is the use of declaring constructor as private?..

Answer / ravikiran

In order to restrict the class to get subclassed

Is This Answer Correct ?    6 Yes 6 No

what is the use of declaring constructor as private?..

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

Post New Answer

More Core Java Interview Questions

what is sendredirect?

7 Answers   TCS,


What is difference between printf and scanf?

0 Answers  


Why we cannot override static method?

0 Answers  


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.

5 Answers  


How to count occurrences of each duplicate element in a list {a,b,d,c,a,b} ? Thanks in Advance

2 Answers   TCS,






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.

7 Answers   HCL, Wipro,


Are primitives objects?

0 Answers  


what is check p object in java

1 Answers   TCS,


What modifiers may be used with an inner class that is a member of an outer class in java programming?

0 Answers  


Is it possible to use string in the switch case?

0 Answers  


Can arraylist hold different types java?

0 Answers  


Can we make constructors static?

0 Answers  


Categories