Please, can anybody answer me that when to use getInstance() and which class having getInstance(),I could not find that method in class Class also.

Questions by Divya6171

Showing Answers 1 - 1 of 1 Answers


  • Nov 1st, 2012

getInstance() method is written inside a class to access the instance of the class from other class.

Basically, this is used to ensure that only one instance of the particular class has been created.
e.g., public static Class1 getInstance(Context context){
if(sInstance == null){
sInstance = new Class1(context);
return sInstance;
* When You need to access any method of this java class Class1, you can call :
* Here I have used this to implement Singleton Pattern of Java.

  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