-
Notifications
You must be signed in to change notification settings - Fork 0
/
AAAAY_singletonClass.java
54 lines (46 loc) · 1.03 KB
/
AAAAY_singletonClass.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class cofeemachine
{
private float cofeeqty;
private float milkqty;
private float waterqty;
private float sugarqty;
static private cofeemachine my = null ;
private cofeemachine()
{
cofeeqty = 1 ;
milkqty = 1 ;
waterqty = 1 ;
sugarqty = 1 ;
}
public void fillwater(float qty)
{
waterqty = qty ;
}
public void fillsugar(float qty)
{
sugarqty = qty;
}
public float getcofee()
{
return 1.23f;
}
static cofeemachine getInstance()
{
if (my == null)
my=new cofeemachine();
return my ;
}
}
public class AAAAY_singletonClass {
public static void main(String arg[])
{
cofeemachine m1 = cofeemachine.getInstance();
cofeemachine m2 = cofeemachine.getInstance();
cofeemachine m3 = cofeemachine.getInstance();
System.out.println(m1+" "+m2+" "+m3);
if(m1==m2 && m1==m3)
{
System.out.println("same");
}
}
}