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 casting?

3 Answers   BMC,


What does 3 dots mean in java?

0 Answers  


Explain the inheritance?

0 Answers  


How can we handle runtime exceptions? write one sample program? Can we write runtime exceptions beside the throws key word? if yes write sample program?

1 Answers   Huawei,


What are the properties of thread?

0 Answers  






What is the Layout for ToolBar?

1 Answers  


Is 0 a prime number?

0 Answers  


finalize() method?

5 Answers  


What is arraylist e?

0 Answers  


we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.

0 Answers  


How do you include a string in java?

0 Answers  


What are different types of multitasking?

0 Answers  


Categories