多态性是重载的另一个术语吗? [英] Is polymorphism another term for overloading?

查看:27
本文介绍了多态性是重载的另一个术语吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多态是重载的另一种说法吗?

Is polymorphism another term for overloading?

推荐答案

No;重载是用不同数量的参数创建一个具有相同名称的方法,或者使用其他类型的参数.

No; overloading is creating a method with the same name with a different amount of parameters, or with parameters which are of another type.

多态性是关于跨各种类型(都具有相同的基本类型")更改特定方法的实现/功能.

Polymorphism is about changing the implementation / functionality of a specific method across various types (which all have the same 'base-type').

重载:

public class TestClass
{
    public void DoSomething( int a, int b ) {}

    public void DoSomething( int a, int b, string x ) {}
}

多态性:

public abstract class Base
{
    public abstract DoSomething();
}

public class A : Base
{
    public override DoSomething()
    {
         Console.WriteLine("I am A");
    }
}

public class B : Base
{
     public override DoSomething()
     {
         Console.WriteLine("I am B");
     }
}

这篇关于多态性是重载的另一个术语吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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