OCA Java SE 8 Mock Exam Review - OCA Mock Question 5


A class Course is defined in a package com.java2s.

Given that the physical location of the corresponding class file is /mycode/com/java2s/Course.class and execution takes place within the mycode directory, which of the following lines of code, when inserted at // INSERT CODE HERE, will import the Course class into the class MyCourse?

         // INSERT CODE HERE 
         class MyCourse { 
             Course c; 
  1. import mycode.com.java2s.Course;
  2. import com.java2s.Course;
  3. import mycode.com.java2s;
  4. import com.java2s;
  5. import mycode.com.java2s*;
  6. import com.java2s*;




A is incorrect.

The path of the imported class used in an import statement reflects the package and subpackage that a class is in but not related to the class's physical location.

C and E are incorrect. The class's physical location isn't specified in the import statement.

D and F are incorrect. java2s is a package. To import a package and its members, the package name should be followed by .*, as follows:

import com.java2s.*;