mardi 12 avril 2016

Java - Overloading Test code

I am new to java and I got asked to identify the errors in this code and revise them. What are the problems in this code and how can I fix it? When I run it, the errors lie in public static int max and public static float max. Thanks!!

public class OverloadingTest {

    public static void main(String[] args) {

       System.out.println(max(1, 2));

   }


    public static int max(int num1, int num2){

          if (num1 >= num2)

          return num1;
         else
             return num2;
    }

    public static int max(int x, int y){

          if (x >= y)

            return x;
          else
             return y;

   } 

    public static float max(int x, int y){

         if (x >= y)

            return x;
         else
             return y;

   }

 }

Aucun commentaire:

Enregistrer un commentaire