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

2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?

1810


What is a numeric literal?

505


Explain some best practices you would apply while using collection in java?

544


How java uses the string and stringbuffer classes?

489


Why we use protected in java?

509






What is comparable and comparator interface? List their differences

558


What is the size of an array?

526


Can a class be a super class and a sub-class at the same time? Give example.

765


Why are there no global variables in java?

560


What is collection class in java?

515


What is the r character?

566


What is java volatile?

519


Why is string buffer better than string ?

574


what is synchronization and why is it important? : Java thread

562


How concurrent hashmap works?

584