本帖最后由 重新开始 于 2013-10-28 11:08 编辑
public enum Blood
{
A, B, AB, O
}
//定义父类
public class Father
{
string firstname;
public string Firstname
{
get { return firstname; }
set { firstname = value; }
}
decimal wealth;
public decimal Wealth
{
get { return wealth; }
set { wealth = value; }
}
Blood blood;
public Blood Blood
{
get { return blood; }
set { blood = value; }
}
//父类的构造函数
public Father(string firstname, decimal wealth, Blood blood)
{
Firstname = firstname;
Wealth = wealth;
Blood = blood;
}
}
public class Son : Father
{
//定义儿子类的构造函数函数,通过base调用父类构造函数给子类字段赋值。
//???红色字体firstname一直提示 “test3.Father.firstname”不可访问,因为它受保护级别限制,怎么回事,test3是命名空间, //firstname, wealth, blood三个参数访问级别是一样的,为什么单firstname出错???
public Son(string name, decimal wealth, Blood blood): base(firstname, wealth, blood)
{
}
public void PlayGame()
{
Console.WriteLine("我是儿子,会玩游戏。");
}
}
}
|