📄 virtualmethod.cs
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -