Polymorphism vs Overriding vs Overloading

前端 未结 21 2877
北恋
北恋 2020-11-22 01:10

In terms of Java, when someone asks:

what is polymorphism?

Would overloading or overriding be

21条回答
  •  [愿得一人]
    2020-11-22 01:15

    The term overloading refers to having multiple versions of something with the same name, usually methods with different parameter lists

    public int DoSomething(int objectId) { ... }
    public int DoSomething(string objectName) { ... }
    

    So these functions might do the same thing but you have the option to call it with an ID, or a name. Has nothing to do with inheritance, abstract classes, etc.

    Overriding usually refers to polymorphism, as you described in your question

提交回复
热议问题