Java Magazine, May/June 2018
ORACLE COM JAVAMAGAZINE MAY JUNE 2018 92 fix this cumbersome when compared with simply writing PI and the longer form doesnt improve readability in any way no one will be unsure what PI means Of course like any syntax feature that shortens code it should be used judiciously If a static import hides helpful context it might make the code harder to understand and in that case it should probably be avoided The syntax of a static import uses the two keywords import static in that order followed by the fully qualified class name and either the static element to be imported or the asterisk indicating that all static elements of the class are to be made available Here are examples of both approaches import static my package MyClass member or import static my package MyClass Notice that although this feature is called a static import the syntax actually has the keywords in the opposite order that is import static Take care that this doesnt cause you to trip in a real exam situation Now lets consider the options Option A suggests that the code compiles as written However the printJob method is out of scope in the Computer class and for the code presented in the question the compiler rejects printJob with a complaint along the lines of cannot find symbol Therefore option A is incorrect Option B correctly applies the syntax rules just described and it succeeds in making the printJob method available by that short name Option B is therefore the correct answer In option C the suggested change constitutes a regular import of the Printer class However there are two problems here First such an import is redundant because the two classes are in the same package and therefore they are visible to one another anyway The second problem is that importing a class in the simple way does not make the static members available in their unqualified form in the file that performs the import Instead a simple import means
You must have JavaScript enabled to view digital editions.