what is private constructor?what are the uses of writing
private constructor in our program?
Answer Posted / ajay parashar
Private constructor is simple constructor that has private
access modifier.
Private constructors are used for two purposes.
1)to prevent creation of objects outside the class when
there are no instance variables in the class and the
methods of class takes some input parameters and does
processing and returns the result without getting or
setting instance variables like in math class of .NET.
2)When your application requires a class that has only one
instance and you need to provide a global point to access
that instance like in the case of singleton.
| Is This Answer Correct ? | 17 Yes | 7 No |
Post New Answer View All Answers
What is multi level inheritance in java?
Explain about class in java?
How many types of the indexof method are there for strings?
Explain about main thread in java?
What do you understand by copy constructor in java?
Where are register variables stored?
Can we extend a class with private constructor?
Is java a software?
What is Applet Stub Interface ?
what are Hostile Applets?
Can a class extends itself in java?
What is immutable state?
What are strings in physics?
Can we overload the methods by making them static?
What are the elements of java?