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 does java final mean?
Explain listiterator and methods in listiterator?
Explain hashset and its features?
What is flag in java?
What is the point of java?
what is synchronization and why is it important? : Java thread
What is merge sort in java?
What will happen if a thrown exception is not handled?
Can a class extend more than one class?
What does || || mean in math?
Can a set contain duplicates?
What is mysql driver class name?
What is the default value of float and double datatype in java?
What do you know about the garbage collector?
Is hashset ordered?