🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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"));
    }
}
  1. A.int double String
  2. B.int int int
  3. C.double double String
  4. 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 →