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
How to convert string to byte array and vice versa?
What is byte value?
What is comparable and comparator interface? List their differences
What does super keyword do?
What is initial size of arraylist in java?
Differentiate between nested and inner class in java.
what is singleton in java?
State differences between C and Java?
What is the difference between logical data independence and physical data independence?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?
Write a program to print all permutations of string?
Why we use protected in java?
What Is Query Throttling in java?
Can we have any other return type than void for main method?
what is deadlock? : Java thread