41 接口的继承

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 接口 { class Program { static void Main(string[] args) { IBankAccount account = new Bank();//接口的多态 Izhuanzhang youaccount = new Zk(); account.cunkuan(10000); youaccount.cunkuan(30000); youaccount.zhuanzhang(account,25000); //account.qukuan(500); Console.WriteLine("我的余额为{0}",account.Blance); Console.WriteLine("你的余额为{0}", youaccount.Blance); } } class Bank:IBankAccount { private decimal blance; public decimal Blance { get { return blance; } } public void cunkuan(decimal amount) { blance += amount; } public bool qukuan(decimal amount) { if (blance >= amount) { blance -= amount; return true; } else { Console.WriteLine("余额不足,取款失败"); return false; } } } }

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 接口 { interface IBankAccount { bool qukuan(decimal amount);//取款 void cunkuan(decimal ck);//存款 decimal Blance//余额 { get; } } }

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 接口 { interface Izhuanzhang:IBankAccount { bool zhuanzhang(IBankAccount destion, decimal amount); } }

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 接口 { class Zk:Izhuanzhang { private decimal blance; public decimal Blance { get { return blance; } } public void cunkuan(decimal amount) { blance += amount; } public bool qukuan(decimal amount) { if (blance >= amount) { blance -= amount; return true; } else { Console.WriteLine("余额不足,取款失败"); return false; } } public bool zhuanzhang(IBankAccount destion, decimal amount) { bool result = qukuan(amount); if (result == true) { destion.cunkuan(amount); } return result; } } }