

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


public class Utility { public static void main(String []args) { System.out.println(Utility.average(7, 8)); System.out.println(Utility.average(7.0, 8));//7.0f } public static float average(int num1, int num2) { return (num1 + num2)/2.0f; } public static float average(float num1, int num2) { return (num1 + num2)/2.0f; } public static int average(int num1, int num2) { return (num1 + num2)/2; } // Confilict: The above method has the same signature as the first // average }
class Num { private int value; public Num (int update) { value = update; } public void setValue (int update) { value = update; } public String toString () { return value + ""; } }
class ParameterModifier { public void changeValues (int f1, Num f2, Num f3) { f1 = 999; f2.setValue(888); f3 = new Num (777); System.out.println ("After changing the values:"); System.out.println ("f1\tf2\tf3"); System.out.println (f1 + "\t" + f2 + "\t" + f3 + "
n"); } } public class ParameterTester { public static void main (String[] args) { ParameterModifier modifier = new ParameterModifier(); int a1 = 111; Num a2 = new Num (222); Num a3 = new Num (333); modifier.changeValues (a1, a2, a3); System.out.println ("After calling changeValues:"); System.out.println ("a1\ta2\ta3"); System.out.println (a1 + "\t" + a2 + "\t" + a3 + "
n"); } }
After changing the values:
After calling changeValues: