OCA Java SE 8 Mock Exam - OCA Mock Question 32


Given the following statements,

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

which of the following options correctly import the classes Person and Course in the class MyMain?

       a import com.java2s.*; 
         class MyMain {} 

       b import com.java2s; 
         class MyMain {} 

       c import com.java2s.Person; 
         import com.java2s.Course; 
         class MyMain {} 

       d import com.java2s.Person; 
         import com.java2s.*; 
         class MyMain {} 


a, c, d


A is correct. The statement import com.java2s.*; imports all the public members of the package com.java2s in class MyMain.

B is incorrect. Because com.java2s is a package, to import all the classes defined in this package, the package name should be followed by .*:

import com.java2s.*; 

C is correct. It uses two separate import statements to import each of the classes Person and Course individually.

D is correct. The first import statement imports only the class Person in MyClass. But the second import statement imports both the Person and Course classes from the package com.java2s.