Java OCA OCP Practice Question 2397

Question

Given the following signature of method m(), choose the options that correctly overload this method:

public String m(int age, String name, double duration) 
a  private String m(int val, String firstName, double dur)
b  public void m(int val1, String val2, double val3)
c  String m(String name, int age, double duration)
d  float m(double name, String age, byte duration)
e  ArrayList<String> m()
f  char[] m(double numbers)
g   String m()


c, d, e, f, g

Note

Option (a) is incorrect.

Overloaded methods can change the access modifiers, but changing the access modifier alone won't make it an overloaded method.

This option also changes the names of the method parameters, but that doesn't make any difference to a method signature.

Option (b) is incorrect.

Overloaded methods can change the return type of the method, but changing the return type won't make it an overloaded method.

Option (c) is correct.

Changing the placement of the types of the method parameters overloads it.

Option (d) is correct.

Changing the return type of a method and the placement of the types of the method parameters overloads it.

Option (e) is correct.

Changing the return type of a method and making a change in the parameter list overloads it.

Option (f) is correct.

Changing the return type of a method and making a change in the parameter list overloads it.

Option (g) is correct.

Changing the parameter list also overloads a method.




PreviousNext

Related