Consider the following methods:

public static void printSport(double n) {
System.out.print("football ");
printSport((int)(n));
}
public static void printSport(int n) {
System.out.print("basketball ");
}

What is output by the method call printSport(8)?


1. football
2. basketball
3. football basketball
4. football football basketball basketball
5. basketball football

Respuesta :

W0lf93
2. basketball This is a classic case of overloading in C++. You have 2 functions, both named "printSport", but one of the functions receives an input of type double, and the other receives an input of type int. The specified method call passes a parameter of type int, so the version of printSport is called that receives a parameter of type int. And that version of printSport only prints the word "basketball". The other version of printSport is never called at all.
ACCESS MORE