📄 inheritproperties.cs
字号:
using System;
class Package
{
public Package(int W)
{
this.Weight = W;
}
private int weight;
public int Weight
{
set
{
if ((value >= 25) && (value <= 50))
weight = value;
else
weight = -1;
}
get
{
return weight;
}
}
public void showPackage()
{
Console.WriteLine("Weight: {0}", Weight);
}
}
class CardboardBox : Package
{
public CardboardBox(int weight, int paperweight) : base(weight)
{
PaperWeight = paperweight; // Strength of cardboard
}
public void ShowBox()
{
Console.WriteLine("Box supports {0} pounds", BoxWeight);
base.showPackage();
}
private int BoxWeight;
public int PaperWeight
{
set
{
if ((value > 0) && (value <= 100))
BoxWeight = value;
else
BoxWeight = -1;
}
get
{
return BoxWeight;
}
}
}
class clsInheritProperties
{
public static void Main ()
{
CardboardBox Box = new CardboardBox(50, 75);
Box.ShowBox();
Box.PaperWeight = 200;
Box.ShowBox();
Box.PaperWeight = 80;
Box.Weight = 33;
Box.ShowBox();
Box.PaperWeight = 50;
Box.Weight = 200;
Box.ShowBox();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -