| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Java Method Overloading Resolution
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy