using System; // static type "interface" for bank account objects: interface account { int inquiry(); void withdraw(int x); void deposit(int x); } // definition of superclass "generic account" class genaccount { protected int balance; public int inquiry() { return balance; } public virtual void withdraw(int amt) // virtual means overridable { balance -= amt; } // function public virtual void deposit(int amt) { balance += amt; } public genaccount(int b) { balance = b; } } // subclasses: // in Java, the following line would read // "class checking extends genaccount implements account class checking : genaccount, account { private int fee; public checking(int b, int f) : base(b) // calls base class constructor { fee = f; } public override void withdraw(int amt) { balance = balance - amt - fee; } } class savings : genaccount, account { private int bonus; public savings(int bl, int bn) : base(bl) { bonus = bn; } public override void deposit(int amt) { balance = balance + amt + bonus; } } public class objects2 { public static void Main(string[] args) { account a1, a2; // note the static type a1 = new savings(500,2); // note the dynamic type a2 = new checking(500,3); a1.deposit(200); a2.deposit(200); a1.withdraw(100); a2.withdraw(100); Console.WriteLine("a1's balance is "+a1.inquiry()); Console.WriteLine("a2's balance is "+a2.inquiry()); } }