Skip to content

Instantly share code, notes, and snippets.

@laymain
Created July 23, 2012 20:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laymain/3166085 to your computer and use it in GitHub Desktop.
Save laymain/3166085 to your computer and use it in GitHub Desktop.
Java Quiz #45
package com.quiz.pkg;
public class Singleton
{
private static final Singleton INSTANCE = new Singleton();
public static Singleton getInstance()
{
return INSTANCE;
}
private Singleton()
{
// <clinit> are the static initialization blocks for the class.
if (!Thread.currentThread().getStackTrace()[2].getMethodName().equals("<clinit>"))
throw new SecurityException();
}
public void sayHello()
{
System.out.println("Hello World !");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment