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 are strings in physics?
Are arrays immutable in java?
What is class array in java?
Can a private method of a superclass be declared within a subclass?
How does compareto work in java?
What does provide mean construction?
What is considered an anti pattern?
What is thread synchronization in java?
What is the main purpose of serialization in java?
How objects are stored in java?
What are register variables what are the advantages?
Explain scope or life time of local variables in java?
What is the right data type to represent a price in java?
Why is a singleton bad?
What is an array length?