package Singleton;
public class Person {
static private Person p;
int bal;
static long acc=1233;
private Person()
{
bal=500;
}
public static Person getInstance()
{
if(p==null)
{
p=new Person();
}
return p;
}
void deposit(int amt) {
bal+=amt;
System.out.println("bal="+bal);
}
boolean withdraw(int amt) {
if(bal<amt)
return false;
bal-=amt;
return true;
}
int checkBalance() {
return bal;
}
}
public class Transaction {
public static void main(String a[]) {
Person atm1=Person.getInstance();
atm1.deposit(1000);
if(atm1.withdraw(2000)==true)
System.out.println("withdraw done");
else
System.out.println("Not possible to withdraw");
Person atm2=Person.getInstance();
atm2.deposit(100);
System.out.println(atm1.checkBalance());
System.out.println(atm2.checkBalance());
}
}