在C#中创建一个虚属性round的代码
public class Square //基类{
public double x;
public Square(double x) //构造方法{
this.x = x;
}
public virtual double Area() //虚方法{
return x*x;
}
public virtual double round //虚属性{
{
get { return (4*x); }
}
}
public class Cube: Square //派生类{
public Cube(double x): base(x) //构造方法{
{
}
public override double Area() //重写方法{
return (6*(base.Area()));
}
public override double round //重写属性{
{
get { return (3*base.round); }
}
}
4.81MB
文件大小:
评论区