class Test1
{
static void Main()
{
Goods g1 = new Num_Goods(3);
g1.UnitPrice = 10;
//g1.GetTotalPrice();
Console.WriteLine(g1);
Goods g2 = new Num_Goods(3);
g2.UnitPrice = 10;
if (g1.Equals(g2))//判断两个对象的引用是否相等
Console.WriteLine(true);
else
Console.WriteLine(false);
}
}
abstract class Goods
{
double unitPrice;
public double UnitPrice
{
get { return unitPrice; }
set { unitPrice = value; }
}
public Goods(double unitPrice)
{
this.unitPrice = unitPrice;
}
public Goods() { }
public abstract double GetTotalPrice();//实现多态
}
class Num_Goods:Goods
{
int num;
public int Num
{
get { return num; }
set { num = value; }
}
public Num_Goods(int num) { this.num = num; }
public override double GetTotalPrice()
{
return num*UnitPrice;
}
public override string ToString()//将对象以字符串的形式返回
{
return UnitPrice+" "+num+" "+GetTotalPrice();
}
}
为什么判断不出来啊啊 啊???:dizzy: |