Java-Quiz: Method Overloading

This Java quiz tests how the compiler chooses between overloaded methods. You will work through the resolution order (exact match, widening, boxing, varargs), calls with null and char, and the overloads that do not compile.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% Java 17

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What does this print?

public class Main {
    static void f(int x) { System.out.println("int"); }
    static void f(long x) { System.out.println("long"); }

    public static void main(String[] args) {
        f(5);
    }
}
Lösung zeigen

A. int The literal 5 is an int, so f(int) is an exact match and wins. f(long) would also work through widening, but an exact match is always preferred.

Darum geht es in diesem Quiz

  • Exact match and widening of primitives
  • Widening beats boxing, boxing beats varargs
  • The most specific method and null arguments
  • Overloads are picked from declared (static) types
  • What does and does not count as an overload

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.