1Z0-819 · Question #145
Given: public class Over { public void analyze(Object o) { System.out.println("I am an object array"); } public void analyze(long[] l) { System.out.println("I am an array"); } public void…
The correct answer is B. The compilation fails due to an error in line 1. Compilation fails because the Over class defines analyze(Object o) twice - Java does not permit two methods with identical signatures in the same class, regardless of what their bodies do. This duplicate method declaration is a compile-time error that prevents the program from…
Question
Options
- AI am an object array
- BThe compilation fails due to an error in line 1
- CI am an array
- DI am an object
How the community answered
(22 responses)- A9% (2)
- B82% (18)
- C5% (1)
- D5% (1)
Explanation
Compilation fails because the Over class defines analyze(Object o) twice - Java does not permit two methods with identical signatures in the same class, regardless of what their bodies do. This duplicate method declaration is a compile-time error that prevents the program from ever running, so the JVM never reaches line 1 or any println statement.
Options A, C, and D are all wrong for the same underlying reason: they assume the program compiles and executes, producing output from one of the three analyze methods. While it's true that an int[] cannot be widened to long[] (making option C unreachable anyway), and that int[] can be autoboxed/upcasted to Object (making A or D plausible candidates), none of this matters because the class itself is illegal.
Memory tip: Before reasoning about which overloaded method gets called, scan the class for duplicate method signatures - same name and same parameter types. If you spot one, the answer is always "compilation fails," and you can skip the overload-resolution analysis entirely.
Topics
Community Discussion
No community discussion yet for this question.