Java OCA OCP Practice Question 2353

Question

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

// contents of MyClass.java 
package com.mypkg; 
import java.util.Date; 
class Student {} 
class Course {} 
  • a The imported class, java.util.Date, can be accessed only in the class Student.
  • b The imported class, java.util.Date, can be accessed by both the Student and Course classes.
  • c Both of the classes Student and Course are defined in the package com .mypkg.
  • d Only the class Student is defined in the package com.mypkg. The class Course is defined in the default Java package.


b, c

Note

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

Option a is incorrect.

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

Option d is incorrect.

If a package statement is defined in the source code file, all the classes, interfaces, and enums defined within it will exist in the same Java package.




PreviousNext

Related