现有如下包结构:
com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class
和类:
class Test { Alpha a; Beta b; Gamma c; }
哪三个必须加入到类 Test 中,以使其通过编译?()
A.package y;
B.package com;
C.import com.x.*;
D.import com.x.y.*
您可能感兴趣的试卷
你可能感兴趣的试题
现有包结构:
com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class
和类:
//insert code here
import com.*;
import com.x.y.*;
class Test { Alpha a; Beta b; Gamma c; }
哪两行分别插入后可允许代码编译?()
A.package com.;
B.import com.x;
C.package com.x;
D.import com.x.Alpha;
现有两个源文件:
package com.sun;
public class PkgAccess {
public static int tiger = 1414;
}
和
import com.sun.PkgAccess;
public class PkgAccess2 {
int x1 = PkgAccess.tiger;
int x2 = tiger;
int x3 = com.sun.PkgAccess.tiger;
int x4 = sun.PkgAccess.tiger;
}
下面哪两项是正确的?()
A.PkgAccess2 类可编译。
B.由于第5 行发生错误编译失败。
C.由于第6 行发生错误编译失败。
D.由于第8 行发生错误编译失败。
A.Java HotSpot 是一种热编译技术,在编译Java 源程序时会被使用
B.Java HotSpot 是一种热编译技术,在运行Java 代码时会被使用
C.Java HotSpot 是一种热编译技术,它会对程序的全部字节码进行优化
D.Java HotSpot 是一种热编译技术,它只对程序的部分字节码进行优化
class Sock {
String size;
String color;
public boolean equals(Object o) {
Sock s = (Sock) o;
return color.equals(s.color);
}
// insert code here
}
哪两个满足 hashCode 的约定?()
A.public int hashCode() { return 343; }
B.public int hashCode() { return size.hashCode (); }
C.public int hashCode() { return color.hashCode (); }
D.public int hashCode() { return (int) (Math.random() * 1000);
- list 是一个合法的集合引用 - getCollection() 返回一个合法集合的引用 哪两个是合法的()
A.for(Object o ; list)
B.for(Object o : list.iterator())
C.for(Object o : getCollection())
D.for(Iterator i = list.iterator(); i.hasNext (); )
1. class SuperFoo {
2. SuperFoo doStuff(int x) {
3. return new SuperFoo();
4. }
5. }
6.
7. class Foo extends SuperFoo {
8. //insert code here
9. }
下面哪三项分别插入到第8行,可以编译?()
A.int doStuff() { return 42; }
B.int doStuff(int x) { return 42; }
C.Foo doStuff(int x) { return new Foo(); }
D.SuperFoo doStuff(int x) { return new Foo(); }
A.访问本地文件系统
B.打开除运行Applet 的主机外的另一个主机的Socket
C.在运行环境中执行另一个程序
D.试图读取不存在的文件
A.使用for 循环
B.使用迭代器Iterator
C.使用枚举器Enumeration
D.使用增强型for 循环
1. class HorseRadish {
2. // insert code here
3. protected HorseRadish(int x) {
4. System.out.println("bok choy");
5. }
6. }
7. class Wasabi extends HorseRadish {
8. public static void main(String [] args) {
9. Wasabi w = new Wasabi();
10. }
11. }
分别插入到第 2 行,哪两项允许代码编译并产生"bok choy" 输出结果?()
A. // just a comment
B. protected HorseRadish() { }
C. protected HorseRadish() { this(42);}
D. protected HorseRadish() { new HorseRadish (42);}
1. class Synapse {
2. protected int gap() { return 7; }
3. }
4.
5. class Creb extends Synapse {
6. // insert code here
7. }
分别插入到第 6 行,哪三行可以编译?()
A. int gap() { return 7; }
B. public int gap() { return 7; }
C. private int gap(int x) { return 7; }
D. protected Creb gap() { return this; }
E. public int gap() { return Integer.getInteger ("42"); }