Consider the following program:
// class Main in mypkg package package mypkg;/*from w w w . ja v a 2s. c o m*/ public class Main { public static void foo() { System.out.println("foo"); } } // class XYZ in mypkg package package mypkg; import static mypkg.*; public class XYZ { public static Main pqr; } // class StatImport import static mypkg.XYZ.*; class StatImport { public static void main(String []args) { // STMT } }
Which one of the following statements will compile without errors when replaced with the line marked with the comment STMT
?
a) foo(); b) pqr.foo(); c) Main.foo(); d) XYZ.pqr.foo();
b)
In this program, the member pqr
is imported statically.
So, the foo()
method can be accessed by qualifying it as pqr.foo()
.
Note that foo()
itself is not imported statically, so it cannot be invoked directly in this program.