Console.WriteLine("圓面積亦為(super)"+test2.superarea());
Console.WriteLine("圓表面積為(this)"+test2.thisarea1());
Console.WriteLine("圓表面積為(省略this)"+test2.thisarea2());
Console.ReadLine();
}
}
class circle
{
protected int radius;
public circle()
{
this.radius=2;
}
public circle(int r)
{
radius=r;
}
public int getradius()
{
return radius;
}
public double getarea()
{
return radius*radius*Math.PI;
}
}
class cylinder:circle
{
int length;
public cylinder():this(2,3)
{
}
public cylinder(int r,int l):base(r)
{
length=l;
}
public int getlength()
{
return length;
}
public new double getarea()
{
return 2*base.getarea()+(2*base.getradius()*Math.PI*length);
}
public double getvolume()
{
return base.getarea()*length;
}
public double thisarea1()
{
return this.getarea();
}
public double thisarea2()
{
return this.getarea();
}
public double superarea()
{
return base.getarea();
}
}
}