TECHI WORLD
Viswanathan S
JAVA Programming
VISWANATHAN S,
ASSISTANT PROFESSOR,
DEPARTMENT OF COMPUTER APPLICATIONS
TECHI WORLD
Viswanathan S
Topics Covered
Overloading Methods.
TECHI WORLD
Viswanathan S
Method Overloading
• Java allows you to define multiple methods in the same class with the same
name but with different parameters.
• Function parameters can differ in terms of their
number, type, or order.
public int add(int a, int b)
{ return a + b; }
public double add(double a, double b)
{ return a + b; }
TECHI WORLD
Viswanathan S
Cont…
• Java compiler determines which version of the method to execute
based on the arguments.
TECHI WORLD
Viswanathan S
Working of Method Overloading
• Method Name: Overloaded methods must have the same name.
• Parameter Lists: The parameter lists of overloaded methods must
differ in at least one of the following ways:
1) The number of parameters.
2) The data types of the parameters.
3) The order of the parameters.
TECHI WORLD
Viswanathan S
Example
public class arithmetic {
public int add (int a, int b) {
return a + b;
}
public double add (double a, double b)
{
return a + b;
}
}
class demo{
public static void main (String args[]){
artithmetic obj = new artithmetic();
int result1 = obj.add(5, 3);
double result2 = obj.add(2.5, 4.3);
System.out.println(result1);
System.out.println (result2);
}
}
TECHI WORLD
Viswanathan S
Benefit
• Method overloading is a useful technique to provide multiple ways
to perform similar operations.
TECHI WORLD
Viswanathan S
THANK YOU
S.VISWANATHAN
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER APPLICATIONS

OVerloaad Methods in JAVA OOPS Conceptss

  • 1.
    TECHI WORLD Viswanathan S JAVAProgramming VISWANATHAN S, ASSISTANT PROFESSOR, DEPARTMENT OF COMPUTER APPLICATIONS
  • 2.
    TECHI WORLD Viswanathan S TopicsCovered Overloading Methods.
  • 3.
    TECHI WORLD Viswanathan S MethodOverloading • Java allows you to define multiple methods in the same class with the same name but with different parameters. • Function parameters can differ in terms of their number, type, or order. public int add(int a, int b) { return a + b; } public double add(double a, double b) { return a + b; }
  • 4.
    TECHI WORLD Viswanathan S Cont… •Java compiler determines which version of the method to execute based on the arguments.
  • 5.
    TECHI WORLD Viswanathan S Workingof Method Overloading • Method Name: Overloaded methods must have the same name. • Parameter Lists: The parameter lists of overloaded methods must differ in at least one of the following ways: 1) The number of parameters. 2) The data types of the parameters. 3) The order of the parameters.
  • 6.
    TECHI WORLD Viswanathan S Example publicclass arithmetic { public int add (int a, int b) { return a + b; } public double add (double a, double b) { return a + b; } } class demo{ public static void main (String args[]){ artithmetic obj = new artithmetic(); int result1 = obj.add(5, 3); double result2 = obj.add(2.5, 4.3); System.out.println(result1); System.out.println (result2); } }
  • 7.
    TECHI WORLD Viswanathan S Benefit •Method overloading is a useful technique to provide multiple ways to perform similar operations.
  • 8.
    TECHI WORLD Viswanathan S THANKYOU S.VISWANATHAN ASSISTANT PROFESSOR DEPARTMENT OF COMPUTER APPLICATIONS