什么是继承和多态性之间的区别? [英] what's the difference between inheritance and polymorphism?

查看:200
本文介绍了什么是继承和多态性之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以给我继承和多态的一个简单的例子,所以它可能是完全清晰易懂?

can you give me a simple example of inheritance and polymorphism, so it could be fully clear and understandable?

使用C#将使其更清晰,因为我已经。学会了

using C# would make it more clear, as I already learned it.

PS:导师,书我们已经有了在本地语言(阿拉伯语)

P.S: the tutors, books we've got are in native language, (arabic)

抱歉,如果这个问题似乎很容易,即使在你们愚蠢的,但这些概念被认为是硬;如果你不完全了解他们,那么你失败了。

sorry if that question seemed so easy, even silly on you guys, but these concepts are considered hard; if you don't fully understand them, then you fail.

推荐答案

让我们用我最喜欢的动词,我们发现:

Let's use my favorite verb and we find:

http://en.wikipedia.org/wiki/Polymorphism_% 28computer_science%29

http://msdn.microsoft.com/en-us/library/ms173152%28v=vs.80%29.aspx

多态性与传承是关键,需要将要-根深蒂固和基本概念,C#和面向对象的编程。他说你知道C#,而不是这就像知道如何说英语,没有的字母是什么概念。对不起,是生硬的,但它是真实的。

Polymorphism and Inheritance are pivotal, need-to-be-ingrained and fundamental concepts to C# and object oriented programming. saying you know C# and not this is like knowing how to speak English and have no concept of what the alphabet is. Sorry to be blunt, but it is true.

从上面的链接维基(这不是我的),这里是多态的例子(转换为C#... )

From the Wiki link above (this is not mine), here is an example of Polymorphism (converted to C#...)

public class Animal
{
    public virtual String talk() { return "Hi"; }
    public string sing() { return "lalala"; }
}

public class Cat : Animal
{
    public override String talk() { return "Meow!"; }
}

public class Dog : Animal
{
    public override String  talk() { return "Woof!"; }
    public new string sing() { return "woofa woofa woooof"; }
}

public class CSharpExampleTestBecauseYouAskedForIt
{
    public CSharpExampleTestBecauseYouAskedForIt()
    {
        write(new Cat());
        write(new Dog());
    }

    public void write(Animal a) {
        System.Diagnostics.Debug.WriteLine(a.talk());
    }

}

这篇关于什么是继承和多态性之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆