class Cust { String name; int ID; String PWD; int money; static String bankName = "建设银行"; int selfNum = 0; static int allNum = 0; Cust(){ name = ""; ID = 0; PWD = ""; money = 0; allNum++; selfNum = allNum; } Cust(String newName,int newID,String newPWD,int newMoney){ name = newName; ID = newID; PWD = newPWD; money = newMoney; allNum++; selfNum = allNum; } void getMoney(int newMoney){ money = money - newMoney; } void setMoney(int neawMoney){ money = money + newMoney; } void search(){ System.out.println("所属银行:" + Cust.bankName); System.out.println("您是本银行的" + allNum + "个顾客中的第" + selfNum + "个顾客"); System.out.println("户名:" + name); System.out.println("账号:" + ID); System.out.println("账号余额" + money); } void changePWD(String newPWD){ PWD = newPWD; } void setInfo(String newName,int newID,String newPWD,int newMoney){ name = newName; ID = newID; PWD = newPWD; money = newMoney; } } class Demo{ public static void main(String[] args){ Cust st1 = new Cust("Tom",100,"11111",10000); Cust st2 = new Cust(); st1.setMoney(5000); st1.getMoney(3000); st1.changePWD("Tom"); st1.search(); st2.setInfo("Jerry",200,"22222",10000); st2.setMoney(10000); st2.getMoney(5000); st2.changePWD("Jerry"); st2.search(); } }
·构造方法的重载