多态意义
来源:互联网 发布:国家数据库安全 编辑:程序博客网 时间:2024/05/22 04:23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
/// <summary>
/// 多态的意义:允许派生类修改其父类的行为(方法),派生类比父类更具有个性,在代码跑起来的时候,跟JS很类似,子类覆盖掉了父类的一些方法
/// </summary>
class Program
{
static void Main(string[] args)
{
animal[] a = new animal[3];
a[0] = new animal();
a[1] = new fish();
a[0].sleep();
a[1].sleep();
Console.ReadLine();
}
}
public class animal
{
public virtual void sleep()
{
Console.WriteLine("animal all need sleep");
}
}
public class fish : animal
{
public override void sleep()
{
Console.WriteLine("fish sleeping with eye_open");
}
}
public class dog : animal
{
public override void sleep()
{
Console.WriteLine("dog sleeping with eye_closed");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
/// <summary>
/// 多态的意义:允许派生类修改其父类的行为(方法),派生类比父类更具有个性,在代码跑起来的时候,跟JS很类似,子类覆盖掉了父类的一些方法
/// </summary>
class Program
{
static void Main(string[] args)
{
animal[] a = new animal[3];
a[0] = new animal();
a[1] = new fish();
a[0].sleep();
a[1].sleep();
Console.ReadLine();
}
}
public class animal
{
public virtual void sleep()
{
Console.WriteLine("animal all need sleep");
}
}
public class fish : animal
{
public override void sleep()
{
Console.WriteLine("fish sleeping with eye_open");
}
}
public class dog : animal
{
public override void sleep()
{
Console.WriteLine("dog sleeping with eye_closed");
}
}
}
- 多态意义
- 多态的使用意义
- 多态机制的意义及实现
- 49-多态的概念和意义
- 意义
- 意义
- 意义
- 意义
- 意义
- 意义
- C++编程-多态的意义:流程的反转控制
- 浅谈多态机制的意义及实现
- 浅谈多态机制的意义及实现
- 多态案例_多态的意义_多态成立的三个条件
- 请简述面向对象的多态的特性及意义
- JAVA笔记-多态的意义(向上转型与向下转型)
- 英语句型中主动态表示被动意义
- 关于ANSYS模态结果各项的意义
- AJAX第一个程序
- C#几个经常用到的字符串的截取
- Linux开机程序内幕(2)
- Cookie的介绍
- 编程技术面试的五大要点
- 多态意义
- Java FTP上传下载单个文件示例代码
- git原理分析【转】
- 析构函数定义为虚函数
- 将一个二维数组转换城datatable。
- unix环境高级编程-4.17-sylmink和readlink函数
- 援引Yaphets的话:我又不淡定了
- 《java与模式》读书笔记之八----阶段小结
- 第一个WP7应用--大学课程表