public static void Main()
Plant [] p = new Plant[3];
p[0] = new Plant(1,"fall");
p[1] = new Tree(2,"fall",true);
p[2] = new Flower(1.5,"fall","yellow",5);
for (i=0; i<p.Length; i++)
Console.WriteLine(((Tree)p[i]).SpringEatable());
Console.WriteLine(p.ToString());
public Plant (double height, string season)
public void AddHeight (double num)
this.height = this.height + num;
public virtual bool IsSell ()
public double GetHeight ()
public string GetSeason ()
public void SetHeight (double height)
public void SetSeason (string season)
public override string ToString ()
return "height = " + this.height + "\nseason = " + this.season;
public class Tree : Plant
public Tree (double height, string season, bool eat) : base (height,season)
public override bool IsSell ()
return base.IsSell() && this.eatable;
public bool SpringEatable ()
return this.eatable && this.season.Equals("Spring");
public bool GetEatable ()
public void SetEatable (bool eatable)
public override string ToString ()
return base.ToString() + "\neatable = " + this.eatable;
public class Flower : Plant
public Flower (double height, string season, string col, int num) : base (height,season)
public override bool IsSell ()
return base.IsSell() && this.numDays>1;
public void Check2FlowerHeight (Flower other, double num)
if (this.height < other.height)
else if (this.height > other.height)
Console.WriteLine("same height");
public string GetColor ()
public void SetColor (string color)
public void SetNumDays (int numDays)
public override string ToString ()
return base.ToString() + "\ncolor = " + this.color + "\nnumDays = " + this.numDays;