What is singleton class?

Answer Posted / vimal eldose george

Singleton gives only one instance.

class Single{

static int objCreated = 0;
private Single(){
}
public static Single getThis(){
if(objCreated==0)
{
return new Single();
ob=1;
}else
{
return this;
}
}

}

Is This Answer Correct ?    32 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the object and class classes used for?

569


What happens when you add a double value to a string?

549


Can we use String with switch case?

675


When should a function throw an exception?

605


What is consumer interface?

562






Can a static member function access member variable of an object?

566


What is an object in java and how is it created?

591


What is generic class?

652


What is valid keyword in java?

565


how its run?

577


Why are lists ordered in java?

551


If an application has multiple classes in it, is it okay to have a main method in more than one class?

543


How do you achieve polymorphism in java?

530


What is a method header?

554


Explain the difference between collection api and stream api in java8?

517