what is the use of declaring constructor as private?

Answer Posted / ranganathkini

By declaring the class constructor as private, other classes
cannot create instances of the class.

This design is usually used in singleton patterns.

Is This Answer Correct ?    22 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is return code?

551


What do you mean by platform independence? What is an interface?

561


How do you calculate square roots?

566


What do you mean by Function Overloading in java?

620


What is a class component?

599






What technique can be employed to compare two strings?

566


What are anonymous inner classes?

558


Why singleton pattern is better than creating singleton class with static instance?

528


How do you do descending order in java?

517


Does java have a compiler?

551


What are the uses of synchronized keyword?

550


What does n mean?

515


Can we declare main () method as non static?

512


State some advantages of java?

708


What does  mean in regex?

565