Java Method Overloading Resolution
Consider the following DataProcessor class, which contains several overloaded process methods.
public class DataProcessor {
public void process(Object data) { /* implementation A */ }
public void process(String text) { /* implementation B */ }
public void process(Integer number) { /* implementation C */ }
public void process(int value) { /* implementation D */ }
}
Now, consider the following code segment that utilizes the DataProcessor class:
DataProcessor dp = new DataProcessor();
String str = "hello";
Integer intObj = 42;
int intPrim = 42;
Object obj = "world";
dp.process(str); // Call 1
dp.process(intObj); // Call 2
dp.process(intPrim); // Call 3
dp.process(obj); // Call 4
Which statement correctly identifies the implementation invoked by each method call?
A
Call 1: B, Call 2: D, Call 3: C, Call 4: B
B
All calls use implementation A because Object is the most general type
C
Call 1: B, Call 2: C, Call 3: D, Call 4: A
D
Call 1: A, Call 2: D, Call 3: C, Call 4: B
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE