Why getInstance() method is used along with class declaration in Java?

Showing Answers 1 - 12 of 12 Answers

SUNIL S D

  • Mar 16th, 2015
 

This is mainly used when there is need of creating an instance of the class.but, when the constructor of class is declared as private.(we cannot create object of object of such class, even inheritance is not possible). So, we use getInstance method.

  Was this answer useful?  Yes

sunilbrahmajosyula

  • Jan 4th, 2016
 

It mainly used in singleton class. In the singleton class we will be creating only one object. Where as this getInstance(); will make sure that there is only one copy of an Instance i.e.,copy of an object and returns the single object

  Was this answer useful?  Yes

komalnk

  • Mar 1st, 2016
 

This is mainly used when there is need of creating an instance of the class.but, when the constructor of class is declared as private. (We cannot create object of object of such class, even inheritance is not possible). So, we use getInstance() method.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions