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 hotjava?
What is difference between final and immutable?
What is native method in java?
What is a generic code?
How many types of java are there?
What is Java Reflection API? Why it’s so important to have?
Describe 2 different ways to concatenate two strings.
What is singleton math?
What causes memory leak in java?
What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?
What are the access modifiers in java?
Explain Basics of OOP Language in java
Can we declare register variable as global?
What is a treeset in java?
What are the java ide's? Explain