📄 sealed.cs
字号:
using System;
//abstract sealed class MyClass{}是错误的
sealed class Square //封固类,不能被继承
{
public double x;
public double y;
public Square(double m,double n)
{
x=m;
y=n;
}
public double Area()
{
return x*y;
}
}
class Square1
{
public double x,y;
public Square1(double m,double n)
{
x=m;
y=n;
}
public virtual double F()
{
return (x*y);
}
}
class Cube:Square1
{
public double height;
public Cube(double x,double y,double h):base(x,y)
{
height=h;
}
public sealed override double F()//调用基类的方法并指明派生类不能再覆盖这个方法
{
return base.F()*height;
}
}
//class MainClass:MyClass是错误的
class MainClass
{
public static void Main()
{
Square square;
Console.WriteLine("calculating the area of the square.....");
Console.Write("please input the length:");
string s=Console.ReadLine();
double m=double.Parse(s);
Console.Write("please input the width:");
string str=Console.ReadLine();
double n=double.Parse(str);
square=new Square(m,n);
Console.WriteLine("the area of the square:{0}",square.Area());
Console.WriteLine("calculating the volumn of the cube......");
Cube mycube;
Console.Write("please input the length:");
s=Console.ReadLine();
m=double.Parse(s);
Console.Write("please input the width:");
str=Console.ReadLine();
n=double.Parse(str);
Console.Write("please input the height:");
string height=Console.ReadLine();
double h=double.Parse(height);
mycube=new Cube(m,n,h);
Console.WriteLine("the volumn of the cube:{0}",mycube.F());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -