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








Question

Given the following contents of the Java source code file MyClass.java, select the correct options:

// contents of MyClass.java 
package com.java2s; 
import java.util.Date; 
class Student {} 
class Course {} 
  1. The imported class, java.util.Date, can be accessed only in the class Student.
  2. The imported class, java.util.Date, can be accessed by both the Student and Course classes.
  3. Both of the classes Student and Course are defined in the package com.java2s.
  4. Only the class Student is defined in the package com.java2s. The class Course is defined in the default Java package.




Answer



b, c

Note

You can define multiple classes, interfaces, and enums in a Java source code file.

A is incorrect. The import statement applies to all the classes, interfaces, and enums defined within the same Java source code file.

D is incorrect. If a package statement is defined in the source code file, it covers all of the classes, interfaces, and enums defined within the same Java package.