Given the following class definition, what is the maximum number of import statements that can be discarded and still have the code compile?
For this question, assume that the MyClass class is defined only in the mypkg package.
package planetarium; import java.lang.*; import mypkg.*; // w w w. j a v a2 s. com import java.lang.Object; import mypkg.MyClass; public class Observer { public void find(MyClass v) {} }
D.
The import statements for mypkg.* and mypkg.MyClass are redundant import statements, since only the class MyClass is used, and one of them can be safely removed.
The import statements java.lang.* and java.lang.Object are both not required as java.lang is automatically imported in every Java class.
Three of the import statements can be safely removed.
The correct answer is Option D.