Quiz de Java: 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.

Médio 10 perguntas ~6 minutos Aprovação com 80% Java 17

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 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);
    }
}
Mostrar a resposta

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.

O que este quiz cobre

  • 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

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.