- class Program
- {
- static void Main(string[] args)
- {
- ChineseP p1 = new ChineseP();
- p1.Name = "张三";
- p1.Age = 18;
- p1.Sex='男';
- p1.Id = 19999924;
- p1.SayHello();
- Console.ReadKey();
- }
- }
- class Person
- {
- string name;
- public string Name
- {
- get { return name; }
- set { name = value; }
- }
- int age;
- public int Age
- {
- get { return age; }
- set { age = value; }
- }
- char sex;
- public char Sex
- {
- get { return sex; }
- set { sex = value; }
- }
- public void SayHello()
- {
- Console.WriteLine("大家好,我叫{0},我今年{1}岁了,我是{2}生", name, age, sex);
- }
- }
- class ChineseP : Person
- {
- int id;
- public int Id
- {
- get { return id; }
- set { id = value; }
- }
- public new void SayHello()
- {
- Console.WriteLine("我的id是{0}", id);
- }
- }
复制代码
|