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


Please Help Members By Posting Answers For Below Questions

Which class contains a method: cloneable or object?

542


How many types of the indexof method are there for strings?

494


Can you declare the main method as final?

531


What things should be kept in mind while creating your own exceptions in java?

635


What is a “stateless” protocol ?

563






What do you mean by light weight and heavy weight components?

561


Differentiate storage classes on the basis of their scope?

676


What is basic syntax?

553


What access modifiers can be used for methods?

563


What is a conditional equation?

565


Is string pool garbage collected?

554


What is return keyword in java?

569


How do you use compareto?

554


Is age a discrete variable?

529


What is a parameter example?

533