日期:2014-05-20 浏览次数:20806 次
public abstract class computercomp { public string Description{get;set;} public abstract double cost() { return 0; } } public class CPU1 : computercomp { computercomp _comp; public CPU1(computercomp comp) { _comp = comp; } public override double Cost() { return 200 + _comp.Cost(); } } public class HD500: computercomp { computercomp _comp; public HD500(computercomp comp) { _comp = comp; } public override double Cost() { return 700 + _comp.Cost(); } } public class Memory256: computercomp { computercomp _comp; public Memory256(computercomp comp) { _comp = comp; } public override double Cost() { return 50 + _comp.Cost(); } } public class Case: computercomp { public override double Cost() { return 200; } } //... public static void main() { computercomp comp = new Case(); comp = new Memory256(comp); comp = new CPU1(comp); comp = new HD500(comp); double price = comp.Cost(); }