what is private constructor?what are the uses of writing
private constructor in our program?
Answer Posted / poonam suryawanshi
When we create a private constructor, we cannot create
object of the class directly from a client. So we will use
private constructor when we do not want instances of the
class to be created by any external client. Even it does not
allow us to inheritance of the class in another class.
Example Utility functions in project will have no instance
and be used without creating instance, as creating instances
of the class would be waste of time. When we create the
Private Constructor we have to make all the Variables and
Function as static.
| Is This Answer Correct ? | 6 Yes | 3 No |
Post New Answer View All Answers
Explain restrictions for using anonymous inner classes?
Can we overload the methods by making them static?
What is the main purpose of java?
Why do I need to declare the type of a variable in java?
How many types of keywords are there?
What is general methodology?
What is the difference between normal report & matrix report?
What is int argc char * argv?
Describe what a thread-local variable is in java?
Can we overload the main() method?
What is a for loop in java?
What is rule of accessibility in java?
Is void a keyword in java?
How to disable caching on back button of the browser?
Can we return null in java?