Skip to content

Instantly share code, notes, and snippets.

@zeeshanlakhani
Created November 14, 2011 17:32
Show Gist options
  • Save zeeshanlakhani/1364543 to your computer and use it in GitHub Desktop.
Save zeeshanlakhani/1364543 to your computer and use it in GitHub Desktop.
Simple Singleton Example in Java
import java.io.*;
import java.util.*;
class Singleton {
private static Singleton _Instance;
private Singleton()
{
}
public static Singleton GetInstance()
{
if (_Instance == null)
_Instance = new Singleton();
return _Instance;
}
public void PrintHello()
{
System.out.println("Hello");
}
}
public class TestSing {
public static void main (String args[]){
Singleton s = Singleton.GetInstance();
//SAME INSTANCE
Singleton a = Singleton.GetInstance();
s.PrintHello();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment