10. class Foo { 11. static void alpha() { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true?()A、 Foo.beta() is a valid invocation of beta().B、 Foo.alpha() is a valid invocation of alpha().C、 Method beta() can directly call method alpha().D、 Method alpha() can directly call method beta().
10. class Foo { 11. static void alpha() { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true?()
- A、 Foo.beta() is a valid invocation of beta().
- B、 Foo.alpha() is a valid invocation of alpha().
- C、 Method beta() can directly call method alpha().
- D、 Method alpha() can directly call method beta().
相关考题:
Given:Which three methods, inserted individually at line 14, will correctly complete class Two?() A.int foo() { /* more code here */ }B.void foo() { /* more code here */ }C.public void foo() { /* more code here */ }D.private void foo() { /* more code here */ }E.protected void foo() { /* more code here */ }
Given:Which code, inserted at line 16, will cause a java.lang.ClassCastException?() A.Alpha a = x;B.Foo f = (Delta)x;C.Foo f = (Alpha)x;D.Beta b = (Beta)(Alpha)x;
现有包结构: 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;
class One { void foo() {} } class Two extends One { //insert method here } Which three methods, inserted individually at line 14, will correctly complete class Two?()A、 int foo() { /* more code here */ }B、 void foo() { /* more code here */ }C、 public void foo() { /* more code here */ }D、 private void foo() { /* more code here */ }E、 protected void foo() { /* more code here */ }
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?()A、 The application will crash.B、 The code on line 29 will be executed.C、 The code on line 5 of class A will execute.D、 The code on line 5 of class B will execute.E、 The exception will be propagated back to line 27.
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行,将编译但是会在运行时产生异常?() A、 a2.m2();B、 ((Beta)a2).m2();C、 ((Alpha)a2).m2();D、 ((Gamma)a2).m2();
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?()A、 This code will compile.B、 This code demonstrates proper design of an is-a relationship.C、 This code demonstrates proper design of a has-a relationship.D、 A Java programmer using the Team class could remove Player objects from a Team object.
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?()A、 import sun.scjp.Color.*;B、 import static sun.scjp.Color.*;C、 import sun.scjp.Color; import static sun.scjp.Color.*;D、 import sun.scjp.*; import static sun.scjp.Color.*;E、 import sun.scjp.Color; import static sun.scjp.Color.GREEN;
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?() A、 Alpha a = x;B、 Foo f= (Delta)x;C、 Foo f= (Alpha)x;D、 Beta b = (Beta)(Alpha)x;
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?() A、 TestedB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.
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?()A、 Compilation fails.B、 The code compiles and the output is 2.C、 If lines 16, 17 and 18 were removed, compilation would fail.D、 If lines 24, 25 and 26 were removed, compilation would fail.E、 If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.F、 If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.
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?()A、 public void foo() { /* more code here */ }B、 private void foo() { /* more code here */ }C、 protected void foo() { /* more code here */ }D、 int foo() { /* more code here */ } E、 void foo() { /* more code here */ }
多选题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?()Apublic void foo() { /* more code here */ }Bprivate void foo() { /* more code here */ }Cprotected void foo() { /* more code here */ }Dint foo() { /* more code here */ }Evoid foo() { /* more code here */ }
单选题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?()A Alpha a = x;B Foo f= (Delta)x;C Foo f= (Alpha)x;D Beta b = (Beta)(Alpha)x;
单选题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?()A TestedB Compilation fails.C The code runs with no output.D An exception is thrown at runtime.
多选题Given: Which three methods, inserted individually at line 14, will correctly complete class Two?()Aint foo() { /* more code here */ }Bvoid foo() { /* more code here */ }Cpublic void foo() { /* more code here */ }Dprivate void foo() { /* more code here */ }Eprotected void foo() { /* more code here */ }
多选题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?()AThis code will compile.BThis code demonstrates proper design of an is-a relationship.CThis code demonstrates proper design of a has-a relationship.DA Java programmer using the Team class could remove Player objects from a Team object.
多选题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?()Aimport sun.scjp.Color.*;Bimport static sun.scjp.Color.*;Cimport sun.scjp.Color; import static sun.scjp.Color.*;Dimport sun.scjp.*; import static sun.scjp.Color.*;Eimport sun.scjp.Color; import static sun.scjp.Color.GREEN;
单选题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行,可允许代码编译?()A只有s1B只有s3C只有s1和s3D只有s1和s4
多选题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?()AThe application will crash.BThe code on line 29 will be executed.CThe code on line 5 of class A will execute.DThe code on line 5 of class B will execute.EThe exception will be propagated back to line 27.
单选题现有: 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. 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行,将编译但是会在运行时产生异常?()A a2.m2();B ((Beta)a2).m2();C ((Alpha)a2).m2();D ((Gamma)a2).m2();
多选题class One { void foo() {} } class Two extends One { //insert method here } Which three methods, inserted individually at line 14, will correctly complete class Two?()Aint foo() { /* more code here */ }Bvoid foo() { /* more code here */ }Cpublic void foo() { /* more code here */ }Dprivate void foo() { /* more code here */ }Eprotected void foo() { /* more code here */ }
多选题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?()ACompilation fails.BThe code compiles and the output is 2.CIf lines 16, 17 and 18 were removed, compilation would fail.DIf lines 24, 25 and 26 were removed, compilation would fail.EIf lines 16, 17 and 18 were removed, the code would compile and the output would be 2.FIf lines 24, 25 and 26 were removed, the code would compile and the output would be 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; } 哪两行分别插入后可允许代码编译?()Apackage com.;Bimport com.x;Cpackage com.x;Dimport com.x.Alpha;
单选题Given: Which code, inserted at line 16, will cause a java.lang.ClassCastException?()A Alpha a = x;B Foo f = (Delta)x;C Foo f = (Alpha)x;D Beta b = (Beta)(Alpha)x;
单选题Which code, inserted at line 16, will cause a java.lang.ClassCastException?()A Alpha a=x;B Foo f=(Delta)x;C Foo f=(Alpha)x;D Beta b=(Beta)(Alpha)x;
多选题10. class Foo { 11. static void alpha() { /* more code here */ } 12. void beta() { /* more code here */ } 13. } Which two are true?()AFoo.beta() is a valid invocation of beta().BFoo.alpha() is a valid invocation of alpha().CMethod beta() can directly call method alpha().DMethod alpha() can directly call method beta().