From cd7261d667132da554692aa649ac8ac8f9783e8b Mon Sep 17 00:00:00 2001 From: yang-wenrong <956352682@qq.com> Date: Wed, 26 May 2021 20:40:30 +0800 Subject: [PATCH] 5.26 --- .../Animal.cs" | 48 ++++++++++ .../Program.cs" | 92 +++++++++++++++++++ .../SupermanAndxx.cs" | 74 +++++++++++++++ .../TeacherAndMoney.cs" | 87 ++++++++++++++++++ .../car.cs" | 60 ++++++++++++ 5 files changed, 361 insertions(+) create mode 100644 "\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Animal.cs" create mode 100644 "\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Program.cs" create mode 100644 "\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SupermanAndxx.cs" create mode 100644 "\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/TeacherAndMoney.cs" create mode 100644 "\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/car.cs" diff --git "a/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Animal.cs" "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Animal.cs" new file mode 100644 index 0000000..4933b41 --- /dev/null +++ "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Animal.cs" @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + class Animal + { + public void eat() { + Console.WriteLine("吃"); + } + } + interface Iclimb { + void climb(); + } + interface Iswim { + void swim(); + } + class cat:Animal,Iclimb + { + public void climb() { + Console.WriteLine("猫猫会爬树"); + } + } + class dog : Animal, Iswim + { + public void swim() + { + Console.WriteLine("狗狗会狗刨"); + } + } + class duck : Animal, Iswim + { + public void swim() + { + Console.WriteLine("鸭子会游泳"); + } + } + class Money : Animal, Iclimb + { + public void climb() + { + Console.WriteLine("猴子会爪巴"); + } + } +} diff --git "a/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Program.cs" "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Program.cs" new file mode 100644 index 0000000..8b4d7c2 --- /dev/null +++ "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/Program.cs" @@ -0,0 +1,92 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + class Program + { + static void Main(string[] args) + { + test4(); + + } + public static void test1() { + //1、音乐老师(既是老师,又是运动员),需要有一种结构,音乐老师继承老师,同时继承运动员。 + //程序员(既是员工,又是作家),需要有一种结构,程序员继承员工,同时继承作家。 + Teacher p1 = new Teacher("英语","李四"); + p1.print(); + p1.Ires(); + + ProgramMoney p2 = new ProgramMoney("员工","张三"); + p2.print(); + p2.Ires(); + } + public static void test2() { + //2、猫、狗、鸭、猴,(吃、游泳、爬树) + + cat cat = new cat(); + dog dog = new dog(); + duck duck = new duck(); + Money money = new Money(); + + TestIswim(dog); + TestIclimb(cat); + + TestAnimal(cat); + TestAnimal(dog); + + Animal a = cat; //>=< + cat = (cat)a; //<=> + + } + + public static void test3() { + //3、蝙蝠战车的例子 + BMWCar bmwCar1 = new BMWCar("宝马", "750"); + bmwCar1.run(); + + BMWCar bmwCar2 = new BMWCar("宝马", "X5"); + bmwCar2.run(); + + Batman batCar = new Batman("蝙蝠战车", "第一代"); + batCar.run(); + batCar.fly(); + } + public static void test4() { + //4、子类:飞机、小鸟、超人 + //父类:交通工具、动物 + //接口 + superman s1 = new superman(); + s1.eat(); + s1.fly(); + s1.land(); + s1.takeoff(); + + bird b1 = new bird(); + b1.takeoff(); + b1.layEggs(); + b1.land(); + b1.fly(); + + plane p1 = new plane(); + p1.fly(); + p1.land(); + p1.takeoff(); + p1.carryPassange(); + } + public static void TestIswim(Iswim swim) { + swim.swim(); + } + public static void TestIclimb(Iclimb climb) + { + climb.climb(); + } + public static void TestAnimal(Animal a) + { + a.eat(); + } + } +} diff --git "a/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SupermanAndxx.cs" "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SupermanAndxx.cs" new file mode 100644 index 0000000..6381012 --- /dev/null +++ "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/SupermanAndxx.cs" @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + class SupermanAndxx + { + + } + interface Iflyable + { + void takeoff(); + void fly(); + void land(); + + } + class vehicle + { + + } + class superman : Animal, Iflyable + { + public void takeoff() + { + Console.WriteLine("超人限载5人有载人能力(双手 双脚 嘴),乘客危险请勿超速"); + } + public void fly() + { + Console.WriteLine("会飞"); + } + public void land() + { + Console.WriteLine("能安全着陆"); + } + } + class bird : Animal, Iflyable + { + public void takeoff() + { + Console.WriteLine("鸟没有承载能力"); + } + public void fly() + { + Console.WriteLine("会飞"); + } + public void land() + { + Console.WriteLine("能安全着陆"); + } + public void layEggs() { + Console.WriteLine("还会下蛋"); + } + } + class plane : vehicle, Iflyable { + public void takeoff() + { + Console.WriteLine("飞机有承载能力"); + } + public void fly() + { + Console.WriteLine("能飞"); + } + public void land() + { + Console.WriteLine("能安全着陆"); + } + public void carryPassange() { + Console.WriteLine("能承载上百的乘客"); + } + } +} diff --git "a/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/TeacherAndMoney.cs" "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/TeacherAndMoney.cs" new file mode 100644 index 0000000..074bf5a --- /dev/null +++ "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/TeacherAndMoney.cs" @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + class person + { + //1、音乐老师(既是老师,又是运动员),需要有一种结构,音乐老师继承老师,同时继承运动员。 + //程序员(既是员工,又是作家),需要有一种结构,程序员继承员工,同时继承作家。 + + private String _name; + public string name { get => this._name; set => this._name = value; } + + + + public person() + { + + } + public person(string name) + { + this._name = name; + } + + public virtual void print() + { + Console.Write("我叫{0}", this._name); + } + + + } + class Teacher : person, Ires + { + private String _res; + public string res { get => this._res; set => this._res = value; } + + public Teacher() + { + + } + public Teacher(string res, string name) : base(name) + { + this._res = res; + } + public override void print() + { + base.print(); + Console.Write("我是个{0}老师", this._res); + } + public void Ires() + { + Console.WriteLine("我还是个运动员"); + } + + } + interface Ires + { + void Ires(); + } + + class ProgramMoney:person,Ires + { + private String _res; + public string res { get => this._res; set => this._res = value; } + + public ProgramMoney() + { + + } + public ProgramMoney(string res, string name) : base(name) + { + this._res = res; + } + public override void print() + { + base.print(); + Console.Write("我是个{0}", this._res); + } + public void Ires() + { + Console.WriteLine("我还是个作家"); + } + } +} diff --git "a/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/car.cs" "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/car.cs" new file mode 100644 index 0000000..d96fba7 --- /dev/null +++ "b/\347\254\2543\346\254\241\344\275\234\344\270\232/\346\235\250\346\226\207\350\215\243/car.cs" @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + class car + { + private string _brand; + private string _type; + public string brand { get => this._brand; set => this._brand = value; } + public string type { get => this._type; set => this._type = value; } + + public car() { + + } + public car(string brand,string type) { + this.brand = brand; + this.type = type; + } + public void run() { + Console.WriteLine("这辆车的品牌是{0},型号是{1},能动能跑",this._brand,this._type); + } + + } + interface Ifire { + void Fire(); + } + interface Ifly { + void fly(); + } + + class Batman : car, Ifly { + public Batman(string brand,string type):base(brand,type) { + + } + public void fly() { + Console.WriteLine("{0},型号是{1}的车还能飞行", base.brand, this.type); + } + } + class BMWCar : car, Ifire + { + public BMWCar(string brand, string type) : base(brand, type) + { + + } + + public void Fire() + { + + } + + public void fly() + { + + } + } +} -- Gitee