what is private constructor?what are the uses of writing
private constructor in our program?

Answer Posted / poonam suryawanshi

When we create a private constructor, we cannot create
object of the class directly from a client. So we will use
private constructor when we do not want instances of the
class to be created by any external client. Even it does not
allow us to inheritance of the class in another class.

Example Utility functions in project will have no instance
and be used without creating instance, as creating instances
of the class would be waste of time. When we create the
Private Constructor we have to make all the Variables and
Function as static.

Is This Answer Correct ?    6 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we make sure main() is the last thread to finish in java program?

922


What is the diffrence between inner class and nested class?

796


What is the main use of generics in java?

708


What about interrupt() method of thread class ?

814


What is the difference between synchronized and synchronized block?

780


What are data types in oop?

766


What is exception propagation?

819


What is serialversionuid?

768


Explain what are final variable in java?

784


What is public static?

729


Is singleton class immutable?

716


What’s the difference between unit, integration and functional testing?

816


What is a variable simple definition?

777


Is intellij better than eclipse?

757


What is the syntax and characteristics of a lambda expression?

785