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


Please Help Members By Posting Answers For Below Questions

What is the difference between preemptive scheduling and time slicing?

824


What is ++ a in java?

757


What is the reason behind using constructors and destructors?

787


Where are global variables stored?

693


What is the use of default method in interface in java?

759


What are the different data types in java?

739


What is module in project?

726


What is the properties class in java programming?

735


Explain public static void main(string args[]) in java.

719


Can I import same package/class twice?

689


What is java used for?

773


What is tostring () method?

759


Can we write any code after throw statement?

811


What is the purpose of a parameter?

773


How to split a string in java?

872