Method Overloading
Method Overloading
> Method /function: A method is a module which is used simultaneously at different instances in the
program.
For example:
> Header public int add() Body return(value).The statement which sends back the value from a
method is called program return statement and issued at the end of the program which is a function
terminator.
> A method is invoked or called by providing the method name followed by the parameters to be
sent enclosed in parenthesis.
For example, a method with prototype as float peri(float 1, float b) can be called in the mainprogram
as: res = peri(lb).
Formal parameter:
Parameter is a variable used with method signature that receives a value during method call.
When the parameter values are received from the caller, then it is called formal parameter
.
METHOD OVERLOADING
Actual Parameter: If the values are passed to the method during its call from the caller, then it is
actual parameter.
> Ways to invoke methods: A method is invoked by two methods - call by value or call by reference
depending upon the ways the arguments are passed to the methods.
Process of passing the reference of actual arguments to the formal parameters and any
change in the formal parameters will be reflected in the actual parameters also.
> A method terminates when either a return statement is encountered or last statement in the
method is executed.
> A method may contain several return statements but only one of them gets executed.
The method of type void does not return a value and thus it cannot be used in expressions.
> Pure method or Accessor takes objects as arguments but does not modify the state of the objects.
> Impure method or mutator takes objects on an argument and changes the state of the objects.
Method overloading:
Method with the same name but used for different purposes is called as overloaded
methods.
It is implemented through polymorphism.
Compiler finds the best match of the method arguments and the parameter list during
program compilation called static binding.
> Method prototype: It is the first line of method definition that tells the program about the type of
value returned and number/type of arguments.
> Method signature: It refers to the number and types of arguments. It is a part of method
prototype.
> Recursive function: A function which calls by itself is called as recursive function.,
METHOD OVERLOADING
> Static method: lt belongs to a class which can be called without the object of a class. static
keyword is added before the static method name.
> Non-static method: Every method in Java is non-static that can access any static method and static
variable without using the object of the class. This method must not have static keyword in the
method name