forked from ramram43210/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingleton.java
More file actions
30 lines (25 loc) · 802 Bytes
/
Copy pathSingleton.java
File metadata and controls
30 lines (25 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Singleton
{
// Static member holds only one instance of the Singleton class
private static Singleton singletonInstance;
// SingletonExample prevents any other class from instantiating
private Singleton()
{
}
// Providing Global point of access
public static Singleton getSingletonInstance()
{
if( null == singletonInstance )
{
singletonInstance = new Singleton();
System.out.println("Inside null check , Object is Created : " +singletonInstance.toString());
System.out.println(" ----------------------------------------------------- ");
}
return singletonInstance;
}
public void printSingleton()
{
System.out.println("Inside print Singleton object : " +singletonInstance.toString());
System.out.println("");
}
}