Java OCA OCP Practice Question 1698

Question

Given the following class, which of these alternatives are valid ways of referring to the class from outside of the package net.mypkg?

package net.mypkg;

public class Main {
  // ...
}

Select the two correct answers.

  • (a) By simply referring to the class as Main.
  • (b) By simply referring to the class as mypkg.Main.
  • (c) By simply referring to the class as net.mypkg.Main.
  • (d) By importing with net.mypkg.*, and referring to the class as Main.
  • (e) By importing with net.*, and referring to the class as mypkg.Main.


(c) and (d)

Note

A class or interface name can be referred to by using either its fully qualified name or its simple name.

Using the fully qualified name will always work, but in order to use the simple name it has to be imported.

By importing net.mypkg.* all the type names from the package net.mypkg will be imported and can now be referred to using simple names.

Importing net.* will not import the subpackage mypkg.




PreviousNext

Related