GeekInterview.com
Series: Subject: Topic:
Question: 7 of 246

getInstance()...

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.
Asked by: Divya6171 | Member Since Jun-2012 | Asked on: Aug 20th, 2012

View all questions by Divya6171

Showing Answers 1 - 1 of 1 Answers
RITENDRA

Answered On : 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 :
Class1.getInstance().method1();
* Here I have used this to implement Singleton Pattern of Java.

  
Login to rate this answer.

Give your answer:

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

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.