Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?()  public class Q4a39 {  int a = 1;   int b = 1;   int c = 1;   class Inner {   int a = 2;  int get() {   int c 

题目

Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?()  public class Q4a39 {  int a = 1;   int b = 1;   int c = 1;   class Inner {   int a = 2;  int get() {   int c = 3;   // insert statement here  return c;   }   }  Q4a39() {   Inner i = new Inner();   System.out.println(i.get());  }   public static void main(String args[]) {   new Q4a39();   }   }  

  • A、c = b;
  • B、c = this.a;
  • C、c = this.b;
  • D、c = Q4a39.this.a;
  • E、c = c;

相似考题
更多“Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?()  public class Q4a39 {  int a = 1;   int b = 1;   int c = 1;   class Inner {   int a = 2;  int get() {   int c =”相关问题
  • 第1题:

    Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?()    public class Qf575 {   // insert declaration of a native method here   }  

    • A、native public void setTemperature(int kelvin);
    • B、private native void setTemperature(int kelvin);
    • C、protected int native getTemperature();
    • D、public abstract native void setTemperature(int kelvin);
    • E、native int setTemperature(int kelvin) {}

    正确答案:A,B

  • 第2题:

    Which line contains a constructor in this class definition?()   public class Counter { // (1)   int current, step;   public Counter(int startValue, int stepValue) { // (2)   set(startValue);   setStepValue(stepValue);  }   public int get() { return current; } // (3)   public void set(int value) { current = value; } // (4)   public void setStepValue(int stepValue) { step = stepValue; } // (5)  }  

    • A、Code marked with (1) is a constructor
    • B、Code marked with (2) is a constructor
    • C、Code marked with (3) is a constructor
    • D、Code marked with (4) is a constructor
    • E、Code marked with (5) is a Constructor

    正确答案:B

  • 第3题:

    10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  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、 newFoo() { public int bar(){return 1; } }
    • D、 new class Foo { public int bar() { return 1; } }

    正确答案:C

  • 第4题:

    Given the following class, which statements can be inserted at position 1 without causing the code to fail compilation?()   public class Q6db8 {   int a;   int b = 0;   static int c;   public void m() {   int d;   int e = 0;   // Position 1   }   } 

    • A、a++;
    • B、b++;
    • C、c++;
    • D、d++;
    • E、e++;

    正确答案:A,B,C,E

  • 第5题:

    public class Score implements Comparable {  private int wins, losses;  public Score(int w, int 1) { wins = w; losses = 1; }  public int getWins() { return wins; }  public int getLosses() { return losses; }  public String toString() {  return “<“ + wins + “,“ + losses + “>”; }  // insert code here  }  Which method will complete this class?() 

    • A、 public int compareTo(Object o) {/*mode 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

  • 第6题:

    Given the following code:     public class Person{     int arr[] = new int[10];  public static void main(String a[]) {     System.out.println(arr[1]);     }     }  Which statement is correct?() 

    • A、 When compilation some error will occur.
    • B、 It is correct when compilation but will cause error when running.
    • C、 The output is zero.
    • D、 The output is null.

    正确答案:A

  • 第7题:

    1. public class Blip {  2. protected int blipvert(int x) { return 0; }  3. }  4. class Vert extends Blip {  5. // insert code here  6. }  Which five methods, inserted independently at line 5, will compile?()  

    • A、 public int blipvert(int x) { return 0; }
    • B、 private int blipvert(int x) { return 0; }
    • C、 private int blipvert(long x) { return 0; }
    • D、 protected long blipvert(int x, int y) { return 0; }
    • E、 protected int blipvert(long x) { return 0; }
    • F、 protected long blipvert(long x) { return 0; }
    • G、protected long blipvert(int x) { return 0; }

    正确答案:A,C,D,E,F

  • 第8题:

    多选题
    Which lines of code are valid declarations of a native method when occurring within the declaration of the following class?()    public class Qf575 {   // insert declaration of a native method here   }
    A

    native public void setTemperature(int kelvin);

    B

    private native void setTemperature(int kelvin);

    C

    protected int native getTemperature();

    D

    public abstract native void setTemperature(int kelvin);

    E

    native int setTemperature(int kelvin) {}


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

  • 第9题:

    多选题
    Given the following class, which statements can be inserted at position 1 without causing the code to fail compilation?()   public class Q6db8 {   int a;   int b = 0;   static int c;   public void m() {   int d;   int e = 0;   // Position 1   }   }
    A

    a++;

    B

    b++;

    C

    c++;

    D

    d++;

    E

    e++;


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

  • 第10题:

    多选题
    Which statements can be inserted at the indicated position in the following code to make the program write 1 on the standard output when run?()  public class Q4a39 {  int a = 1;   int b = 1;   int c = 1;   class Inner {   int a = 2;  int get() {   int c = 3;   // insert statement here  return c;   }   }  Q4a39() {   Inner i = new Inner();   System.out.println(i.get());  }   public static void main(String args[]) {   new Q4a39();   }   }
    A

    c = b;

    B

    c = this.a;

    C

    c = this.b;

    D

    c = Q4a39.this.a;

    E

    c = c;


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

  • 第11题:

    单选题
    Which line contains a constructor in this class definition?()   public class Counter { // (1)   int current, step;   public Counter(int startValue, int stepValue) { // (2)   set(startValue);   setStepValue(stepValue);  }   public int get() { return current; } // (3)   public void set(int value) { current = value; } // (4)   public void setStepValue(int stepValue) { step = stepValue; } // (5)  }
    A

    Code marked with (1) is a constructor

    B

    Code marked with (2) is a constructor

    C

    Code marked with (3) is a constructor

    D

    Code marked with (4) is a constructor

    E

    Code marked with (5) is a Constructor


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

  • 第12题:

    单选题
    What will be the result of attempting to compile and run the following program?()   public class Q28fd {   public static void main(String args[]) {   int counter = 0;   l1:   for (int i=10; i i) break l2;   if (i == j) {   counter++;   continue l1;   }   }   counter--;   }   System.out.println(counter);  }   }
    A

    The program will fail to compile.

    B

    The program will not terminate normally.

    C

    The program will write 10 to the standard output.

    D

    The program will write 0 to the standard output.

    E

    The program will write 9 to the standard output.


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

  • 第13题:

    What will be the result of attempting to compile and run the following code?()   public class Q6b0c {   public static void main(String args[]) {  int i = 4;  float f = 4.3;   double d = 1.8;   int c = 0;   if (i == f) c++;   if (((int) (f + d)) == ((int) f + (int) d))  c += 2;   System.out.println(c);   }   }  

    • A、The code will fail to compile.
    • B、0 will be written to the standard output.
    • C、1 will be written to the standard output.
    • D、2 will be written to the standard output.
    • E、3 will be written to the standard output.

    正确答案:A

  • 第14题:

    Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }  

    • A、public int sum(int a, int b) { return a + b; }
    • B、public int sum(long a, long b) { return 0; }
    • C、abstract int sum();
    • D、private long sum(long a, long b) { return a + b; }
    • E、public long sum(long a, int b) { return a + b; }

    正确答案:A,E

  • 第15题:

    What will be written to the standard output when the following program is run?()   public class Q8499 {   public static void main(String args[]) {  double d = -2.9;   int i = (int) d;  i *= (int) Math.ceil(d);  i *= (int) Math.abs(d);   System.out.println(i);   }   }

    • A、12
    • B、18
    • C、8
    • D、9
    • E、27

    正确答案:C

  • 第16题:

    What will be written to the standard output when the following program is run?()   class Base {  int i;  Base() {   add(1);   }   void add(int v) {  i += v;  }   void print() {  System.out.println(i);  }   }   class Extension extends Base {  Extension() {  add(2);  }   void add(int v) {  i += v*2;  }  }   public class Qd073 {   public static void main(String args[]) {  bogo(new Extension());  }   static void bogo(Base b) {  b.add(8);  b.print();   }   }  

    • A、9
    • B、18
    • C、20
    • D、21
    • E、22

    正确答案:E

  • 第17题:

    What will be the result of attempting to compile and run the following program?()   public class Q28fd {   public static void main(String args[]) {   int counter = 0;   l1:   for (int i=10; i<0; i--) {   l2:  int j = 0;   while (j < 10) {   if (j > i) break l2;   if (i == j) {   counter++;   continue l1;   }   }   counter--;   }   System.out.println(counter);  }   }   

    • A、The program will fail to compile.
    • B、The program will not terminate normally.
    • C、The program will write 10 to the standard output.
    • D、The program will write 0 to the standard output.
    • E、The program will write 9 to the standard output.

    正确答案:A

  • 第18题:

    public class Parent {     int change() {…}     }  class Child extends Parent {     }  Which methods can be added into class Child?()    

    • A、 public int change(){}
    • B、 int chang(int i){}
    • C、 private int change(){}
    • D、 abstract int chang(){}

    正确答案:A,B

  • 第19题:

    What will be written to the standard output when the following program is run?()   public class Qcb90 {   int a;   int b;   public void f() {  a = 0;   b = 0;   int[] c = { 0 };   g(b, c);   System.out.println(a + " " + b + " " + c[0] + " ");   }   public void g(int b, int[] c) {   a = 1;  b = 1;  c[0] = 1;  }   public static void main(String args[]) {   Qcb90 obj = new Qcb90();   obj.f();   }   }  

    • A、0 0 0
    • B、0 0 1
    • C、0 1 0
    • D、1 0 0
    • E、1 0 1

    正确答案:E

  • 第20题:

    多选题
    Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?()   public class Qdd1f {   public long sum(long a, long b) {  return a + b;  }   // insert new method declaration here  }
    A

    public int sum(int a, int b) { return a + b; }

    B

    public int sum(long a, long b) { return 0; }

    C

    abstract int sum();

    D

    private long sum(long a, long b) { return a + b; }

    E

    public long sum(long a, int b) { return a + b; }


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

  • 第21题:

    单选题
    What will be the result of attempting to compile and run the following code?()   public class Q6b0c {   public static void main(String args[]) {  int i = 4;  float f = 4.3;   double d = 1.8;   int c = 0;   if (i == f) c++;   if (((int) (f + d)) == ((int) f + (int) d))  c += 2;   System.out.println(c);   }   }
    A

    The code will fail to compile.

    B

    0 will be written to the standard output.

    C

    1 will be written to the standard output.

    D

    2 will be written to the standard output.

    E

    3 will be written to the standard output.


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

  • 第22题:

    单选题
    Given the following code:     public class Person{ static int arr[] = new int[10];  public static void main(String a[]) {     System.out.println(arr[1];)     }     }  Which statement is correct?()
    A

     When compilation some error will occur.

    B

     It is correct when compilation but will cause error when running.

    C

     The output is zero.

    D

     The output is null.


    正确答案: C
    解析:  int型数组是类对象,它在类被加载时完成初始化,在前面题目中已经有叙述,由于是原始数据类型int,其初始值为0。

  • 第23题:

    单选题
    Given the following code:     public class Person{     int arr[] = new int[10];  public static void main(String a[]) {     System.out.println(arr[1]);     }     }  Which statement is correct?()
    A

     When compilation some error will occur.

    B

     It is correct when compilation but will cause error when running.

    C

     The output is zero.

    D

     The output is null.


    正确答案: D
    解析: 实例变量在类的一个实例构造时完成初始化,而且在类的静态方法中不能直接访问类的非静态成员而只能访问类成员(像上题中一样),类的普通方法可以访问类的所有成员和方法,而静态方法只能访问类的静态成员和方法,因为静态方法属于类,而普通方法及成员变量属于类的实例,类方法(静态方法)不能使用属于某个不确定的类的实例的方法和变量,在静态方法里面没有隐含的this,而普通方法有。