what is private constructor?what are the uses of writing
private constructor in our program?

Answers were Sorted based on User's Feedback



what is private constructor?what are the uses of writing private constructor in our program?..

Answer / sirisha

a constructor which is declared with private accesspecifer,
we can call it is private constructor,so that we can nt
create object from out side of the class, in this way we
can provide security to our class

Is This Answer Correct ?    39 Yes 8 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / gopalramana

no other class does not create instance of this class,we go
private constructor

Is This Answer Correct ?    17 Yes 3 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / 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

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / christian

a common use for a private constructor is to implement the
singletton pattern, which uses a public member variable of
the same type of the class which is defined. A public
getInstance() method uses this private constructor

Is This Answer Correct ?    13 Yes 6 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / neha

we can not create instance of object with new operator.if u
do not want the class to be inherited then we declare the
construtor as private when we used Private Construtor
Static metods are used this construtor are also used for
creating singleton object

Is This Answer Correct ?    7 Yes 0 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / 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

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / udaychow

only once instance of a particular class is allowed.through
private constructor only we can achieve singleton design
pattern.

Is This Answer Correct ?    8 Yes 8 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / nandhakumar

We use private constructor in singleton class:it ve only one
instance,in this case we generally used to ve one static
method (getInstance()).While we cal this method first time
it use private constructor to create instance.next time this
method returns the existin instance..

Is This Answer Correct ?    0 Yes 0 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / neha

In Private Construtor is that
1. We used The Private acess Modifier
2. In Private Construtor We can Not Create the instance Of
this Class in Outside Class
3. We can used only Static Data Member In Private Construtor

Is This Answer Correct ?    1 Yes 2 No

what is private constructor?what are the uses of writing private constructor in our program?..

Answer / amit

Private constructor can be used to make a pure static
class, using it we can create only one instance of class at
the loading time.

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More Core Java Interview Questions

What is an example of declaration?

0 Answers  


What do you mean by jjs in java8?

0 Answers  


What is the use of bin and lib in JDK?

8 Answers   TCS,


can u give one sinario when you use Abstract Class and When you use Interface.

5 Answers   ITC Infotech,


enlist some features of jdk.

0 Answers  






What is hasnext in java?

0 Answers  


How is string stored in java?

0 Answers  


What are the override methods in Object class?

2 Answers   Tech Mahindra, Wipro,


why is S capital in System.out.println ????

6 Answers  


How do listeners work?

0 Answers  


What is java ceil?

0 Answers  


Why is String immutable?

0 Answers   Atos Origin,


Categories