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








Question

Given the following classes, what is the maximum number of imports that can be removed and have the code still compile?

     //Shape.java
     package com.java2s; 
     
     public class Shape { } 


     //Printer.java
     package com.java2s; 
     
     import java.lang.*; 
     import java.lang.System; 
     import com.java2s.Shape; 
     import com.java2s.*; 
     
     public class Printer { 
        public void print(Shape shape) { 
           System.out.println(shape); 
        } 
     } 
     
  1. 0
  2. 1
  3. 2
  4. 3
  5. 4
  6. Does not compile.




Answer


E.

Note

The first two imports can be removed since java.lang is automatically imported.

The second two imports can be removed because Printer and Shape are in the same package.