Anonymous

What Is A Class With A Private Constructor Called In Java?

6

6 Answers

Anonymous Profile
Anonymous answered
Constructors by default are public..
They can be declared as private in case of the singleton classes and   also if the class contain all the constants.singleton classes are those for whom only one object could be made.
In this case when you try making the second object it displays an error..
Anonymous Profile
Anonymous answered
We cannot instantiate the class by another class. It's the main use
sridher yamsani Profile
sridher yamsani answered
Generally by making a constructor as private one can't instantiate the class by creating objects.The following classes generally will have private constructors they are abstract classes and singleton classes.
valcano blast Profile
valcano blast answered
Private constructors can be used in two ways, private constructor can be called by other constructors.
or private constructors can also be called from static methods.

To call a static method on a class you don't need an instance.
So a static method inside the class can create an instance of the class(Static method is inside the class so it will have access to private constructor also).
Gopinath Sundaram Profile
There cannot be private constructors as they are of no use.Constructors are invoked while creating objects,if the construct is private,you cannot create objects of the class from outside and hence there cannot be private constructors.

Answer Question

Anonymous