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


Please Help Members By Posting Answers For Below Questions

What does method mean?

520


What is a variable and constant?

550


What is the hashcode () and equals () used for?

538


What is use of functional interface in java 8? Explain

567


What is module in project?

520






What is stringwriter?

543


Java is pass by value or pass by reference? Explain

536


What is fundamental datatype?

531


Explain all java features with real time examples

1212


5 Coding best practices you learned in java?

640


What are methods?

560


Explain the features of interfaces in java?

558


Why to use nested classes in java? (Or) what is the purpose of nested class in java?

530


Explain super keyword in java.

587


How many types of methods are there?

551