⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sealed.cs

📁 深入浅出C#,学习C#比较好的用例,能够很快掌握C#.
💻 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 + -