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 di

题目

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().

相似考题
参考答案和解析
正确答案:B,C
更多“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 dir”相关问题
  • 第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?()

    • 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.

    正确答案:B,E

  • 第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?()

    • 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.

    正确答案:A,D

  • 第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?() 

    • A、 Alpha a = x;
    • B、 Foo f= (Delta)x;
    • C、 Foo f= (Alpha)x;
    • D、 Beta b = (Beta)(Alpha)x;

    正确答案:B

  • 第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?()

    • 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.

    正确答案:B,E,F

  • 第5题:

    多选题
    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 */ }


    正确答案: A,C,E
    解析: 暂无解析

  • 第6题:

    单选题
    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

     Tested

    B

     Compilation fails.

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.


    正确答案: C
    解析: 暂无解析

  • 第7题:

    多选题
    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.


    正确答案: A,D
    解析: 暂无解析

  • 第8题:

    单选题
    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

    只有s1

    B

    只有s3

    C

    只有s1和s3

    D

    只有s1和s4


    正确答案: D
    解析: 暂无解析

  • 第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.      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();


    正确答案: D
    解析: 暂无解析

  • 第10题:

    多选题
    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.


    正确答案: A,E
    解析: 暂无解析

  • 第11题:

    单选题
    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;


    正确答案: B
    解析: 暂无解析

  • 第12题:

    多选题
    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().


    正确答案: B,C
    解析: 暂无解析

  • 第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行,将编译但是会在运行时产生异常?()  

    • A、 a2.m2();
    • B、 ((Beta)a2).m2();
    • C、 ((Alpha)a2).m2();
    • D、 ((Gamma)a2).m2();

    正确答案:D

  • 第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?()

    • 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;

    正确答案:C,E

  • 第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?()  

    • A、 Tested
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第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?()

    • 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 */ }

    正确答案:A,C,E

  • 第17题:

    单选题
    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;


    正确答案: C
    解析: 暂无解析

  • 第18题:

    多选题
    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 */ }


    正确答案: D,B
    解析: 暂无解析

  • 第19题:

    多选题
    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;


    正确答案: A,B
    解析: 暂无解析

  • 第20题:

    多选题
    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.


    正确答案: D,C
    解析: 暂无解析

  • 第21题:

    多选题
    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 */ }


    正确答案: C,D
    解析: 暂无解析

  • 第22题:

    多选题
    现有包结构:  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;


    正确答案: C,D
    解析: 暂无解析

  • 第23题:

    单选题
    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;


    正确答案: B
    解析: 暂无解析