Tuesday, August 24, 2010

Static Imports



Courtesy of Sun Web Learning Center

Given the two source files:

1.  package com.sun;
2.  public class PkgAccess {
3.    public static int tiger = 1414;
4.  }

And:

1.  import static com.sun.PkgAccess.*;
2.
3.  public class PkgAccess2 {
4.
5.    int x1 = PkgAccess.tiger;
6.    int x2 = tiger;
7.    int x3 = com.sun.PkgAccess.tiger;
8.    int x4 = sun.PkgAccess.tiger;
9.  }

Which two are true? (Choose two.)


A The PkgAccess2 class compiles.
B Compilation fails due to an error on line 5.
C Compilation fails due to an error on line 6.
D Compilation fails due to an error on line 7.
E Compilation fails due to an error on line 8.
F The PkgAccess and PkgAccess2 classes both compile.


B and E are correct. You must use either the fully qualified name or you must use the entire import string.

No comments:

Post a Comment