Given the following code:     1) public void modify() {    

题目
单选题
Given the following code:     1) public void modify() {     2) int i, j, k;     3) i = 100;     4) while ( i > 0 ) {     5) j = i * 2;  6) System.out.println (" The value of j is " + j );     7) k = k + 1;     8) i--;     9) }  10) }  Which line might cause an error during compilation?()
A

 line 4

B

 line 6

C

 line 7

D

 line 8

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Given:Which four code fragments, inserted independently at line 7, will compile?()

A.public void m1() { }

B.protected void m1() { }

C.private void m1() { }

D.void m2() { }

E.public void m2() { }

F.protected void m2() { }

G.private void m2() { }


参考答案:A, B, E, F

第2题:

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

第3题:

What happens when you try to compile and run the following program?

class Mystery{String s;public static void main(String[] args){

Mystery m=new Mystery();m.go();}void Mystery(){s=”constructor”;}void go(){System.out.println(s);}

}()

A.this code will not compile

B.this code compliles but throws an exception at runtime

C.this code runs and “constructor” in the standard output

D.this code runs and writes “null” in the standard output


参考答案:D

第4题:

public class Plant {  private String name;  public Plant(String name) { this.name = name; }  public String getName() { return name; }  }  public class Tree extends Plant {  public void growFruit() { }  public void dropLeaves() { }  }  Which is true?() 

  • A、 The code will compile without changes.
  • B、 The code will compile if public Tree() { Plant(); } is added to the Tree class.
  • C、 The code will compile if public Plant() { Tree(); } is added to the Plant class.
  • D、 The code will compile if public Plant() { this(”fern”); } is added to the Plant class.
  • E、 The code will compile if public Plant() { Plant(”fern”); } is added to the Plant class.

正确答案:D

第5题:

Given the following code:     1) public void modify() {     2) int i, j, k;     3) i = 100;     4) while ( i > 0 ) {     5) j = i * 2;  6) System.out.println (" The value of j is " + j );     7) k = k + 1;     8) i--;     9) }  10) }  Which line might cause an error during compilation?()   

  • A、 line 4
  • B、 line 6
  • C、 line 7
  • D、 line 8

正确答案:C

第6题:

Given: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

第7题:

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

第8题:

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


参考答案:B, C, E

第9题:

interface A { public int getValue() }  class B implements A {  public int getValue() { return 1; }  }  class C extends B {  // insert code here  }  Which three code fragments, inserted individually at line 15, make use of polymorphism?()

  • A、 public void add(C c) { c.getValue(); }
  • B、 public void add(B b) { b.getValue(); }
  • C、 public void add(A a) { a.getValue(); }
  • D、 public void add(A a, B b) { a.getValue(); }
  • E、 public void add(C c1, C c2) { c1.getValue(); }

正确答案:B,C,D

第10题:

Given the following code:     1) class Parent {     2) private String name;     3) public Parent(){}     4) }  5) public class Child extends Parent {     6) private String department;  7) public Child() {}  8) public String getValue(){ return name; }     9) public static void main(String arg[]) {     10) Parent p = new Parent();     11) }  12) }  Which line will cause error?()   

  • A、 line 3
  • B、 line 6
  • C、 line 7
  • D、 line 8
  • E、 line 10

正确答案:D

更多相关问题