Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Method overloading

// Java program to demonstrate working of method
// overloading in Java.
  
public class Sum {
  
    // Overloaded sum(). This sum takes two int parameters
    public int sum(int x, int y)
    {
        return (x + y);
    }
  
    // Overloaded sum(). This sum takes three int parameters
    public int sum(int x, int y, int z)
    {
        return (x + y + z);
    }
  
    // Overloaded sum(). This sum takes two double parameters
    public double sum(double x, double y)
    {
        return (x + y);
    }
  
    // Driver code
    public static void main(String args[])
    {
        Sum s = new Sum();
        System.out.println(s.sum(10, 20));
        System.out.println(s.sum(10, 20, 30));
        System.out.println(s.sum(10.5, 20.5));
    }
}
Comment

method overloading

Method overloading is providing two separate methods in a class 
with the same name but different arguments, while the method return type 
may or may not be different, which allows us to reuse the same method name.
Comment

method overloading

Method overloading is providing 
two separate methods in a class 
with the same name but different arguments,
while the method return type 
may or may not be different, which
allows us to reuse the same method name.
In my framework==
I use implicit wait in Selenium. Implicit wait
is an example of overloading. In Implicit wait
we use different time stamps such as SECONDS, MINUTES, HOURS etc.,
A class having multiple methods with
same name but different parameters 
is called Method Overloading
Comment

Method Overloading

public class methodOverloading{

   public static void main(String[] args) {
      int intNum_01 = 43;
      int intNum_02 = 55;
      double doubleNum_01 = 4.3;
      double doubleNum_02  = 3.23;
      int result_01 = minimumNumFun(intNum_01 , intNum_02 );
      
      // same function name with different parameters
      double result_02 = minimumNumFun(doubleNum_01 , doubleNum_01 );
      System.out.println("Minimum Value = " + result_01);
      System.out.println("Minimum Value = " + result_02);
   }

   // for integer
   public static int minimumNumFun(int n1, int n2) {
      int min;
      if (n1 > n2)
         min = n2;
      else
         min = n1;

      return min; 
   }
   
   // for double
   public static double minimumNumFun(double n1, double n2) {
     double min;
      if (n1 > n2)
         min = n2;
      else
         min = n1;

      return min; 
   }
}
Comment

method overloading

func play(instrument: String) {}
Comment

PREVIOUS NEXT
Code Example
Java :: Java forEach() Method 
Java :: java 8 lambda comparator 
Java :: Add Elements in java map 
Java :: static method in non static class java 
Java :: buy and sell stock 
Java :: how to encrypt password in properties file in spring boot 
Java :: java "-" 
Java :: Send HTTP Get Request with Parameters. 
Java :: kafkalistener annotation pass topic from properties file 
Java :: combobox index out of bound javafx 
Java :: int to integer array in java 
Java :: l datetime anne month jour heure minute second in java 
Java :: intellij java fx new window 
Java :: Unrolling java - from 
Java :: Develop the Java application called Shapes. For this program, use only for loops and the following print statements below to generate the shapes below: 
Java :: instance block in java 
Java :: .code domain 
Java :: zoomin pdf in android studio 
Java :: enable GPS inside of application 
Java :: Java create an object of the non-static class Reptile 
Java :: error: package android.support.v4.content does not exist import android.support.v4.content.LocalBroadcastManager; 
Java :: Iterating The Queue Elements 
Java :: Java Boolean Literals 
Java :: where do you use overriding in framework 
Java :: java requirenonnull 
Java :: javax.servlet.ServletException: javax.servlet.jsp.JspException: Missing message for key 
Java :: how to get data from array list to set java 
Java :: ["org.elasticsearch.bootstrap.startupexception: java.lang.illegalstateexception: failed to obtain node locks, 
Java :: What is the difference between Error and Exception? java 
Java :: why fields should be final in immutable class? 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =