Given the following two classes, each in a different package,
which line inserted below allows the second class to compile?
package mypkg; //from ww w.ja va 2s . c o m public class Main { public void withdrawal(int v) {} public void deposit(int v) {} } ? package mypkg2; // INSERT CODE HERE public class Teller { public void processAccount(int depositSlip, int withdrawalSlip) { withdrawal(withdrawalSlip); deposit(depositSlip); } }
D.
A static import is used to import static members of another class.
In this case, the withdrawal()
and deposit()
methods in the Main class are not marked static.
They require an instance of Main to be used and cannot be imported as static methods.
Therefore, Option D is correct.
If the two methods in the Main class were marked static, then Option A would be the correct answer since wildcards can be used with static imports to import more than one method.
Option B reverses the keywords static and import, while Option C incorrectly imports a class, which cannot be imported via a static import.