真题分析
面向对象程序设计
Package 及 JAR
(1)Given the following Java code:
package test;
class Target {
public String name = "hello";
}
What can directly access and change the value of the variable name?
A. Any class
B. Only the Target class
C. Any class in the test package
D. Any class that extends Target
答案:C
解析:
� 本题考修饰字的存取范围
� Target 为无存取修饰字, 所以本类别的能见度仅在相同的 package 中
� 该变量 name 的存取修饰字为 public, 所以范围最多只能与所属类别相同.
� 因此本题相当简单
(2)A developer is creating a class Book, that needs to access class Paper. The Paper class is
deployed in a JAR named myLib.jar. Which three, taken independently, will allow the developer
to use the Paper class while compiling the Book class? (choose three)
A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar
B. The JAR file is located at $JAVA_HOME/jre/ext/myLib.jar
C. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that
includes /foo/myLib.jar/Paper,class.
D. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that
includes /foo/myLib.jar
E. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac –cp
评论0
最新资源