- Executors
-
Learn
Learn Python Runnable examples, NumPy, pandas, and more Learn AI / Machine LearningNeural networks, ML and LLMs from scratch Learn C & C++ Pointers, memory, STL, and modern C++ Learn C#C# basics, OOP, LINQ, async, and .NET exercises Learn MatplotlibLine, bar, scatter and pie charts with live visualizers Learn RustOwnership, traits, error handling, and threads Learn GoSlices, interfaces, goroutines, and channels Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++ Coding for Kids Learn to code by playing!
- QuizzesNew
- ChallengesNew
- For TeachersNew
- Updates
- Buy me a coffee
Java Method Overloading Quiz
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.
Sample question
Question 1 of 10What 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);
}
}
Show the answer
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.
What this quiz covers
- Exact match and widening of primitives
- Widening beats boxing, boxing beats varargs
- The most specific method and
nullarguments - Overloads are picked from declared (static) types
- What does and does not count as an overload
Questions people ask
Do I need an account?
No. Anyone can play. Sign in to keep your XP, streak, badges and history.
Can I retake it?
Yes. Your best score is kept, and the questions and answers are shuffled each time.