public class Singleton4
extends java.lang.Object
data
.TestSingleton4
Modifier and Type | Class and Description |
---|---|
private static class |
Singleton4.SingletonHolder
SingletonHolder is loaded on the first execution of
Singleton4.getInstance() or the first access to SingletonHolder.INSTANCE,
not before.
|
Modifier and Type | Field and Description |
---|---|
private int |
data
An instance attribute - for illustrative purposes
|
Modifier | Constructor and Description |
---|---|
private |
Singleton4()
The constructor is private so that it is controlled by the class.
Initially the data value is set to 0. |
Modifier and Type | Method and Description |
---|---|
int |
getData()
data getter method |
static Singleton4 |
getInstance() |
void |
setData(int d)
data setter method |
private Singleton4()
data
value is set to 0.public static Singleton4 getInstance()
public int getData()
data
getter methodpublic void setData(int d)
data
setter methodd
- defines the new data value