第5、6章面向对象高级应用.pptVIP

  • 3
  • 0
  • 约2.87万字
  • 约 109页
  • 2017-06-10 发布于北京
  • 举报
1 继承 “继承”这个词的字面含义是: 按照法律或遵照遗嘱接受死者的财产、职务、头衔、地位等。 面向对象方法中的继承与现实世界中的继承的意义基本相同,是指一个类完全继承了另一个类的所有内容,如字段、成员函数等。 继承是一种父母与孩子的关系,孩子从父母那继承了一些父母的特点,并也有着与父母的不同之处。 面向对象的关键特性——继承 继承示例 灯与台灯、壁灯、吊灯之间的继承关系 面向对象的关键特性——继承 继承示例 人与学生、教师、士兵之间的继承关系 class Program { static void Main(string[] args) { B b = new B(); b.Display(); Console.ReadLine(); } } class Program { static void Main(string[] args) { B b = new B(); b.Display(); b.T = hello; b.Dispaly11(); Console.ReadLine(); } } class Program { static void Main(string[] args) { Employee e = new Employee(); e.GetEmployeeInfo(); Console.ReadLine(); } } public class Person { int age; public Person(int age) { this.age=age; } } public class Student : Person { int age,string sex; public Student(int age,string sex): base(age) { this.sex=sex; } } class Program { static void Main(string[] args) { Console.WriteLine(第一次实例化,无参:); Child c = new Child(); Console.WriteLine(); Console.WriteLine(第二次实例化,有参:); Child c1 = new Child(8); Console.ReadLine(); } } class Program { static void Main(string[] args) { Console.WriteLine(第一次实例化,无参:); Child c = new Child(); Console.WriteLine(); Console.WriteLine(第二次实例化,有参:); Child c1 = new Child(8); Console.ReadLine(); Child c2 = new Child(3,4,5); } } public class Person { int age; public Person(int age) { this.age=age; } public void Speak() { Console.writeLine(“speak language”); } } static void Main(string[] args) { Bicycle b = new Bicycle(); b.Wheel(); Tricycle t = new Tricycle(); t.Wheel(); Jeep j = new Jeep();

文档评论(0)

1亿VIP精品文档

相关文档