本文介绍了多态性是过载的另一个术语吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
多态性是过载的另一个术语吗?
Is polymorphism another term for overloading?
推荐答案
否;重载是创建一个具有相同名称,带有不同数量参数或具有另一种类型参数的方法.
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");
}
}
这篇关于多态性是过载的另一个术语吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!