Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me is there anything called private constructor in Java? And why it is been used?

1 Answer

0 votes
by (26.7k points)

Yes, there is a private constructor in Java. Basically, it is used for three major cases are:

1. It helps to prevent instantiation outside the object in the case of singleton, factory method, static-methods-only class.

2. Also, it helps to prevent subclassing.

3. It helps in the case of overloaded constructors.

I hope this will help.

Want to become a Java Expert? Join Java Certification now!!

Want to know more about Java? Watch this video on Java Course | Java Tutorial for Beginners:

Related questions

0 votes
1 answer
asked Oct 17, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...