virtualmethod.cs
来自「这是《ASP.NET编程实作教程》一书中的源文件 如果有此书的朋友不防下载过来参」· CS 代码 · 共 58 行
CS
58 行
using System;
class myShape
{
public virtual double getArea(){return 0;}
public virtual void defineShape(double x,double y){}
public virtual void defineShape(double x){}
public double x;
public double y;
}
class myCircle:myShape
{
public override void defineShape(double r)
{
this.x=r;
}
public override double getArea()
{
return 3.14*this.x*this.x;
}
}
class myRectangle:myShape
{
public override void defineShape(double a,double b)
{
this.x=a;
this.y=b;
}
public override double getArea()
{
return this.x*this.y;
}
}
class virtualMethod
{
public static void Main()
{
double area;
myShape shape;
shape=new myCircle();
shape.defineShape(10);
area=shape.getArea();
Console.WriteLine("the Area is {0}",area);
shape=new myRectangle();
shape.defineShape(10,8);
area=shape.getArea();
Console.WriteLine("the Area is {0}",area);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?