PatternSingleton: Initial commit
This commit is contained in:
19
System Development/PatternSingleton/src/Singleton.java
Normal file
19
System Development/PatternSingleton/src/Singleton.java
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
public class Singleton {
|
||||
|
||||
//create an object of SingleObject
|
||||
private static Singleton instance = new Singleton();
|
||||
|
||||
//make the constructor private so that this class cannot be
|
||||
//instantiated
|
||||
private Singleton(){}
|
||||
|
||||
//Get the only object available
|
||||
public static Singleton getInstance(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void showMessage(){
|
||||
System.out.println("There can be only One!");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user