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 the difference between preemptive scheduling and time slicing?
What is ++ a in java?
What is the reason behind using constructors and destructors?
Where are global variables stored?
What is the use of default method in interface in java?
What are the different data types in java?
What is module in project?
What is the properties class in java programming?
Explain public static void main(string args[]) in java.
Can I import same package/class twice?
What is java used for?
What is tostring () method?
Can we write any code after throw statement?
What is the purpose of a parameter?
How to split a string in java?