本文介绍了尽可能简单地描述多态性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用通俗易懂的方式描述多态性?
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.
更多推荐
尽可能简单地描述多态性
发布评论