← Quiz: Polymorphism: all 10 questions
Quiz: Polymorphism · Question 8 of 10
What does this print? (code)
What does this print?
public class Main {
static String show(int x) { return "int"; }
static String show(double x) { return "double"; }
static String show(String x) { return "String"; }
public static void main(String[] args) {
System.out.println(show(5) + " " + show(5.0) + " " + show("5"));
}
}
- A.int double String
- B.int int int
- C.double double String
- D.String String String
Answer & explanation
Correct answer: int double String
The compiler picks each overload from the argument's type: compile-time polymorphism.
Can you get the rest right without peeking?
Take the timed Quiz: Polymorphism quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →