内测------------使用多态描述动物的运动
来源:互联网 发布:剑网三藏剑男神脸数据 编辑:程序博客网 时间:2024/05/04 18:05
使用多态描述动物的运动
一、语言和环境
A、实现语言
C#
B、环境要求
Visual Studio 2012
二、功能要求
在森林中生活着很多小动物,现创建控制台程序来描述各种动物的运动。如图-3所示。
图-3 抽象方法实现多态
要求:
1、 不同的动物都有执行运动的功能。
2、 3种不同动物对象保存在一个泛型集合中。
3、 不能使用判断语句判断动物类型。
4、 使用抽象方法实现不同动物的多态,不可以使用方法的重载。
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 多态描述动物运动{ class Program { static void Main(string[] args) { List<Animal> list = new List<Animal>(); Console.WriteLine("森林里的小动物快乐的生活着!"); list.Add(new Fish()); list.Add(new Dog()); list.Add(new Birds()); foreach (Animal item in list) { item.Action(); } Console.ReadLine(); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 多态描述动物运动{ public class Fish:Animal { public override void Action() { Console.WriteLine("鱼儿在水里游"); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 多态描述动物运动{ public class Dog:Animal { public override void Action() { Console.WriteLine("狗在地上跑!"); } }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 多态描述动物运动{ public class Birds:Animal { public override void Action() { Console.WriteLine("鸟儿在天上飞!"); } }}
0 0
- 内测------------使用多态描述动物的运动
- [速报酱团队]第二周,如何让我们的单细胞动物运动
- 内部类的描述
- 矩阵的本质-运动的描述
- 转:矩阵的本质-运动的描述
- 矩阵的本质-运动的描述【好】
- 矩阵的本质-运动的描述
- 矩阵的本质-运动的描述
- 矩阵的本质-运动的描述
- 运动捕捉数据的描述ASF/AMC
- 虚拟类--动物描述
- openlayers入门之使用openlayers描述车辆运动轨迹
- 接口的使用(动物问题)
- C++语言 对动物的行为实现多态
- 抽象类,多态的实现_食物,动物,人
- 内部类的描述/什么时候使用/以及所带来的好处
- surfaceView 的使用 运动小球
- 内部类及匿名内部类的详细描述
- Window7 64位旗舰版 安装Oracle 11gR2 安装图解
- 网页前端——JavaScript
- 07-图5 Saving James Bond
- 二级目录与二级域名
- ecshop更换模板名报c.cat_id=".$cid为空错误解决。
- 内测------------使用多态描述动物的运动
- 87 :Jump Game
- 合并查询与正则表达式查询
- Codeforces Round #386 (Div. 2) D
- 【BZOJ 1025】[SCOI2009]游戏
- //控件横向来回抖动
- 高效学习笔记
- Stetho的通信原理
- Centos新建永久网桥