• 2022-05-31
    Which method will complete this class?()
    A: public int compareTo(Object o){/* more code here */}
    B: public int compareTo(Score other){/* more code here */}
    C: public int compare(Score s1, Score s2){/* more code here */}
    D: public int compare(Object o1, Object o2){/* more code here */}
  • B

    内容

    • 0

      下面选项中哪一行代码可以替换题目中注释语句//add code here不会产生编译错误?()请解释原因?publicabstractclassMyClass {publicintconstInt = 5;//add code herepublicvoidmethod() {}} A: public abstract void method(int a); B: constInt = constInt + 5; C: public int method(); D: public abstract void anotherMethod() {}

    • 1

      Which code, inserted at line 15, allows the class Sprite to compile?() A: Foo{public int bar(){return 1;}} B: new Foo{public int bar(){return 1;}} C: new Foo(){public int bar(){return 1;}} D: new class Foo{public int bar(){return 1;}}

    • 2

      public class TestDemo{   private int x = 2;  static int y = 3;  public void method(){     final int i=100;     int j = 10;      class Cinner{  public void mymethod(){  //Here       }    } } }  在Here处可以访问的变量是哪些?() A: x B:  y C:  i D:  j

    • 3

      下面哪个方法不是Object类中定义的( )。 A: public boolean equals() B: public String toString() C: public int compareTo() D: public int hashCode()

    • 4

      读代码: public class Test { public static void main (String args[]) { class Foo { public int i = 3; } Object o = (Object) new Foo(); Foo foo = (Foo)o; System.out.println(foo.i); } } 结果是: