10. class Foo { 11. static void alpha() { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true?()
第1题:
1. public class A { 2. public void method1() { 3. B b=new B(); 4. b.method2(); 5. // more code here 6. } 7. } 1. public class B { 2. public void method2() { 3.C c=new C(); 4. c.method3(); 5. // more code here 6. } 7. } 1. public class C { 2. public void method3() { 3. // more code here 4. } 5. } Given: 25. try { 26. A a=new A(); 27. a.method1(); 28. } catch (Exception e) { 29. System.out.print(”an error occurred”); 30. } Which two are true if a NullPointerException is thrown on line 3 of class C?()
第2题:
public class Team extends java.util.LinkedList { public void addPlayer(Player p) { add(p); } public void compete(Team opponent) { /* more code here */ } } class Player { /* more code here */ } Which two are true?()
第3题:
10. interface Foo {} 11. class Alpha implements Foo {} 12. class Beta extends Alpha {} 13. class Delta extends Beta { 14. public static void main( String[] args) { 15. Beta x = new Beta(); 16. // insert code here 17. } 18. } Which code, inserted at line 16, will cause a java.lang.ClassCastException?()
第4题:
10. interface Foo { 11. int bar(); 12. } 13. 14. public class Beta { 15. 16. class A implements Foo { 17. public int bar() { return 1; } 18. } 19. 20. public int fubar( Foo foo) { return foo.bar(); } 21. 22. public void testFoo() { 23. 24. class A implements Foo { 25. public int bar() { return 2; } 26. } 27. 28. System.out.println( fubar( new A())); 29. } 30. 31. public static void main( String[] argv) { 32. new Beta().testFoo(); 33. } 34. } Which three statements are true?()
第5题:
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
int foo() { /* more code here */ }
void foo() { /* more code here */ }
第6题:
Tested
Compilation fails.
The code runs with no output.
An exception is thrown at runtime.
第7题:
This code will compile.
This code demonstrates proper design of an is-a relationship.
This code demonstrates proper design of a has-a relationship.
A Java programmer using the Team class could remove Player objects from a Team object.
第8题:
只有s1
只有s3
只有s1和s3
只有s1和s4
第9题:
a2.m2();
((Beta)a2).m2();
((Alpha)a2).m2();
((Gamma)a2).m2();
第10题:
Compilation fails.
The code compiles and the output is 2.
If lines 16, 17 and 18 were removed, compilation would fail.
If lines 24, 25 and 26 were removed, compilation would fail.
If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.
If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.
第11题:
Alpha a = x;
Foo f = (Delta)x;
Foo f = (Alpha)x;
Beta b = (Beta)(Alpha)x;
第12题:
Foo.beta() is a valid invocation of beta().
Foo.alpha() is a valid invocation of alpha().
Method beta() can directly call method alpha().
Method alpha() can directly call method beta().
第13题:
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行,将编译但是会在运行时产生异常?()
第14题:
package sun.scjp; public enum Color { RED, GREEN, BLUE } package sun.beta; // insert code here public class Beta { Color g = GREEN; public static void main( String[] argv) { System.out.println( GREEN); } } The class Beta and the enum Color are in different packages. Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile?()
第15题:
interface Beta {} class Alpha implements Beta { String testIt() { return “Tested”; } } public class Main1 { static Beta getIt() { return new Alpha(); } public static void main( String[] args ) { Beta b = getIt(); System.out.println( b.testIt() ); } } What is the result?()
第16题:
Given: 10. class One { 11. void foo() { } 12. } 13. class Two extends One { 14. //insert method here 15. } Which three methods, inserted individually at line 14, will correctly complete class Two?()
第17题:
Alpha a = x;
Foo f= (Delta)x;
Foo f= (Alpha)x;
Beta b = (Beta)(Alpha)x;
第18题:
int foo() { /* more code here */ }
void foo() { /* more code here */ }
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
第19题:
import sun.scjp.Color.*;
import static sun.scjp.Color.*;
import sun.scjp.Color; import static sun.scjp.Color.*;
import sun.scjp.*; import static sun.scjp.Color.*;
import sun.scjp.Color; import static sun.scjp.Color.GREEN;
第20题:
The application will crash.
The code on line 29 will be executed.
The code on line 5 of class A will execute.
The code on line 5 of class B will execute.
The exception will be propagated back to line 27.
第21题:
int foo() { /* more code here */ }
void foo() { /* more code here */ }
public void foo() { /* more code here */ }
private void foo() { /* more code here */ }
protected void foo() { /* more code here */ }
第22题:
package com.;
import com.x;
package com.x;
import com.x.Alpha;
第23题:
Alpha a=x;
Foo f=(Delta)x;
Foo f=(Alpha)x;
Beta b=(Beta)(Alpha)x;