Java OCA OCP Practice Question 527

Question

Given the following classes, which of the following can independently replace

INSERT IMPORTS HERE to make the code compile?

Choose all that apply

package mypkg; //from  w  ww .j  a  v  a  2  s  .  c  om
public class Tank { } 

package mypkg.jellies; 
public class MyClass { } 

package visitor; 
INSERT IMPORTS HERE 
public class Main { 
    public void admire(MyClass my) { } } 
  • A. import mypkg.*;
  • B. import mypkg.*.MyClass;
  • C. import mypkg.jellies.MyClass;
  • D. import mypkg.jellies.*;
  • E. import mypkg.jellies.MyClass.*;
  • F. None of these can make the code compile.


C, D.

Note

Option C is correct because it imports MyClass by classname.

Option D is correct because it imports all the classes in the jellies package, which includes MyClass.

Option A is incorrect because it only imports classes in the mypkg package-Tank in this case-and not those in lower-level packages.

Option B is incorrect because you cannot use wildcard any place other than the end of an import statement.

Option E is incorrect because you cannot import parts of a class with a regular import statement.

Option F is incorrect because options C and D do make the code compile.




PreviousNext

Related