1 // A subclass of the savings account class. 2 // This example illustrates adding instance variables and 3 // overriding a method in the parent class. 4 // Nancy McCracken 3/14/97 5 6 7 public class AccountCmp extends Account 8 { 9 // instance variables 10 // also inherits name, balance, interestrate 11 static double minbalance = 6000.; 12 static double penalty = 20.; 13 14 // constructor method is same as parent 15 public AccountCmp (String n, double b) 16 { super (n, b); } 17 18 // override one method 19 // also inherits getname, getbalance, getbalancedollars, getbalancecents 20 // withdraw, and deposit 21 public double monthactivity() 22 { if (balance < minbalance) balance -= penalty; 23 double newbalance = balance * 24 (double)(Math.pow (1 + (interestrate/12)/30, 30)); 25 double interest = newbalance - balance; 26 balance = newbalance; 27 return interest; 28 } 29 } 30