

Hi,
A class whose number of instances that can be instantiated is limited to one is called a singleton class. Thus, at any given time only one instance can exist, no more.
public class Single {
private static Single a;
private Single() {
}
public static Single getSingle() {
if (a == null) {
a = new Single();
}
return a;
}
public static void main(String... s) {
Single a1 = Single.getSingle();
Single a2 = Single.getSingle();
System.out.println(a1);
System.out.println(a2);
}
}
This program give the out put as-
samar.Single@3e25a5 samar.Single@3e25a5
Thanks.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.