OCA Java SE 8 Building Blocks - OCA Mock Question Building Block 18


Given the following classes, which of the following snippets can be inserted in place of INSERT IMPORTS HERE and have the code compile? (Choose all that apply)

     package com.java2s; 
     public class Shape { 
       boolean printable = false; 

     package com.java2s.beans; 
     public class Shape { 
       boolean printable = true; 

     package filter; 
     public class ShapeFiller { 
       Shape water; 
  1. import com.java2s.*;
  2. import com.java2s.Shape; import com.java2s.beans.*;
  3. import com.java2s.*; import com.java2s.beans.Shape;
  4. import com.java2s.*; import com.java2s.beans.*;
  5. import com.java2s.Shape; import com.java2s.beans.Shape;
  6. None of these imports can make the code compile.


A, B, C.


A is correct because it imports all the classes in the com.java2s package including com.java2s.Shape.

B and C are correct because they import Shape by classname.

Since importing by classname takes precedence over wildcards, these compile.

D is incorrect because Java doesn't know which of the two wildcard Shape classes to use. They both have the Shape class.

E is incorrect because you cannot specify the same classname in two imports, which result in name confliction.