“Methodenüberlastung” Code-Antworten

Methodenüberlastung

// 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));
    }
}
Talented Tuatara

Methodenüberlastung

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; 
   }
}
Outrageous Ostrich

Methodenüberlastung

func play(instrument: String) {}
Impossible Ibis

Ähnliche Antworten wie “Methodenüberlastung”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen