怎么不成功呀
using System;class Test
{
public static void Main()
{
float[] vals={(float)2.0,(float)3.0};
Quad q=new Quad(Val[0],Val[1]);
Triangle t=new Triangle(Val[0],Val[1]);
Console.WriteLine("Quad area is {0}",q.GetArea());
Console.WriteLine("Triangle area is {0}",t.GetArea());
}
}
public abstract class Shape
{
protected float width;
protected float height;
public Shape(float w,float h)
{
width=w;
height=h;
}
public abstract float GetArea();
}
public class Quad:Shape
{
public Quad(float w,float h):base(w,h)
{
}
public override float GetArea()
{
return width*height;
}
}
public class Triangle:Quad
{
public Triangle(float w,float h):base(w,h)
{
}
public override float GetArea()
{
return 0.5F*width*height;
}
}