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 a parameter in matrices?
Difference between default and protected access specifiers?
How can you write a loop indefinitely in java programming?
What are the differences between forwarding () method and sendredirect() methods?
Can java program run without jre?
Which is better list or arraylist in java?
Write a java program that prints all the values given at command-line.
Can we have more than one package statement in source file ?
Can we sort a map in java?
What is <> used for in java?
How to sort array in descending order in java?
Is it necessary for the port addresses to be unique? Explain with reason.
Can a boolean be null java?
How does varargs work in java?
What are 4 pillers of object orinted programming?