MethodOver.md - brainchildservices/curriculum GitHub Wiki
What is polymorphism?
Polymorphism means the ability to take different forms. Method Overloading is a form of polymorphism.
What is Method Signature?
Method Signature includes parameters list i.e. the number of the parameters, order of the parameters, and data types of the parameters. So whatever
comes inside the method parenthesis would define the signature of the method.
What is method overloading?
Two or more than two methods having the same name but different parameters is what we call method overloading in C#. The program would decide which
method it would call based on the arguments it has.
How to achieve method overloading?
Method overloading can be achieved by the following:By changing number of parameters in a methodBy changing the order of parameters in a methodBy using different data types for parameters
Why do we need Method Overloading?
The advantage of method overloading is that it increases the readability of the program because you don't need to use different names for same
action.
Can we overload method by changing the return type?
No. return type of a method is not part of the signature of the method. So we can't do method overloading if the method names and parameter list
are same but with different return type.
Can we declare one overloaded method as static and another one as non-static?
Yes. Overloaded methods can be either static or non static.
Is it possible to have two methods in a class with same method signature but different return types?
No, compiler will give duplicate method error. Compiler checks only method signature for duplication not the return types. If two methods have
same method signature, straight away it gives compile time error.