// base class of account: public class account { // a "private" variable is not visible outside of the class account // a "protected" variable is also visible in subclasses of account // a "public" variable is visible from all other classes and packages // If a variable is not preceeded by public/protected/private, then it's // by default public inside the same package (basically, same directory). protected double balance; public account(double n) { balance=n; } public void deposit(double amt) { balance += amt; } public void withdraw(double amt) { if (amt<=balance) balance -=amt; } public double inquiry() { return balance; } } // subclass "savings" account has an interest rate, which is added to deposits class savings extends account { protected static double interestrate = 0.01; // 1% interest (why static?) public savings(double n) { super(n); } // just call superclass constructor public void deposit(double amt) // override deposit method of superclass { balance += amt + (amt * interestrate); } } // subclass "checking" account charges a fee for each withdraw class checking extends account { protected double fee; // fee charged for each withdraw public checking(double n) { super(n); if (n<1000) fee = 2; else fee = 1; // fee depends on initial balance } // override withdraw method of superclass public void withdraw(double amt) { if (amt+fee<=balance) balance -= amt+fee; } }