Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Is it permissible in java to define two methods in a class that have identical m

ID: 3816603 • Letter: I

Question

Is it permissible in java to define two methods in a class that have identical method names and parameter lists but different return value types or different modifiers?

What is wrong in the following program?

public class Test {

public static void method(int x) {

}

public static int method(int y) {

return y;

}

}

Given two method definitions,

public static double m(double x, double y)

public static double m(int x, double y)

tell which of the two methods is invoked for:

a. double z = m(4, 5);

b. double z = m(4, 5.4);

c. double z = m(4.5, 5.4);

Explanation / Answer

Is it permissible in java to define two methods in a class that have identical method names and parameter lists but different return value types or different modifiers?

No, Signature is considered with name and paramater list only.

What is wrong in the following program?

public class Test {

public static void method(int x) {

}

public static int method(int y) {

return y;

}

}

Same as above question. It has method(int) signature for two method which is not permissible.

Given two method definitions,

public static double m(double x, double y)

public static double m(int x, double y)

tell which of the two methods is invoked for:

a. double z = m(4, 5); - call to double m(int x, double y). It will convert second argument to double (conversion happen such that minimum conversion has a method signature)

b. double z = m(4, 5.4); - call to double m(int x, double y).

c. double z = m(4.5, 5.4); - call to double m(double x, double y)

Is this answered your query, please rate positively.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote