尽可能简单地描述多态性

编程入门 行业动态 更新时间:2024-10-09 00:48:24
本文介绍了尽可能简单地描述多态性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何用通俗易懂的方式描述多态性?

How can polymorphism be described in an easy-to-understand way?

我们可以在 Internet 和书籍上找到很多关于该主题的信息,例如在 Type多态性.但让我们尽量让它变得简单.

We can find a lot of information about the subject on the Internet and books, like in Type polymorphism. But let's try to make it as simple as we can.

推荐答案

这是我的 回答类似的问题.下面是伪 C#/Java 中的多态性示例:

This is from my answer from a similiar question. Here's an example of polymorphism in pseudo-C#/Java:

class Animal { abstract string MakeNoise (); } class Cat : Animal { string MakeNoise () { return "Meow"; } } class Dog : Animal { string MakeNoise () { return "Bark"; } } Main () { Animal animal = Zoo.GetAnimal (); Console.WriteLine (animal.MakeNoise ()); }

Main() 方法不知道动物的类型,它取决于 MakeNoise() 方法的特定实现行为.

The Main() method doesn't know the type of the animal and depends on a particular implementation's behavior of the MakeNoise() method.

更多推荐

尽可能简单地描述多态性

本文发布于:2023-11-29 09:28:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646009.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多态性   简单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!