只有s1
只有s3
只有s1和s3
只有s1和s4
第1题:
现有包结构: 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; } 哪两行分别插入后可允许代码编译?()
第2题:
现有: 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" 输出结果?()
第3题:
1. import java.util.*; 2. class SubGen { 3. public static void main(String [] args) { 4. //insert code here 5. } 6. } class Alpha { } class Beta extends Alpha { } class Gamma extends Beta { } 和四段代码片段: s1. ArrayList〈? extends Alpha〉 list1 = new ArrayList〈Gamma〉(); s2. ArrayList〈Alpha〉 list2 = new ArrayList〈? extends Alpha〉(); s3. ArrayList〈? extends Alpha〉 list3 = new ArrayList〈? extends Beta〉(); s4. ArrayList〈? extends Beta〉 list4 = new ArrayList〈Gamma〉(); ArrayList〈? extends Alpha〉 list5 = list4; 哪些片段分别插入到第4行,可允许代码编译?()
第4题:
Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. private static void process(byte[] b) { } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?()
第5题:
1. class Pizza { 2. java.util.ArrayList toppings; 3. public final void addTopping(String topping) { 4. toppings.add(topping); 5. } 6. } 7. public class PepperoniPizza extends Pizza { 8. public void addTopping(String topping) { 9. System.out.println(”Cannot add Toppings”); 10. } 11. public static void main(String[] args) { 12. Pizza pizza = new PepperoniPizza(); 13. pizza.addTopping(”Mushrooms”); 14. } 15. } What is the result?()
第6题:
1. public interface A { 2. public void doSomething(String thing); 3. } 1. public class AImpl implements A { 2. public void doSomething(String msg) { } 3. } 1. public class B { 2. public A doit() { 3. // more code here 4. } 5. 6. public String execute() { 7. // more code here 8. } 9. } 1. public class C extends B { 2. public AImpl doit() { 3. // more code here 4. } 5. 6. public Object execute() { 7. // more code here 8. } 9. } Which statement is true about the classes and interfaces in the exhibit?()
第7题:
Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?() class A {} class B extends A {} class C extends A {} public class Q3ae4 { public static void main(String args[]) { A x = new A(); B y = new B(); C z = new C(); // insert statement here } }
第8题:
10. class Foo { 11. static void alpha() { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true?()
第9题:
1. class Alpha { void m1() {} } 2. class Beta extends Alpha { void m2() { } } 3. class Gamma extends Beta { } 4. 5. class GreekTest { 6. public static void main(String [] args) { 7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() }; 8. for(Alpha a2 : a) { 9. a2.m1(); 10. if (a2 instanceof Beta || a2 instanceof Gamma) 11. //insert code here 12. } 13. } 14. } 哪一行代码插入到第11行,将编译但是会在运行时产生异常?()
第10题:
Given classes defined in two different files: 1. package util; 2. public class BitUtils { 3. public static void process(byte[]) { /* more code here */ } 4. } 1. package app; 2. public class SomeApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class SomeApp to use the process method of BitUtils?()