多选题Given a pre-generics implementation of a method: What three changes allow the class to be used with generics and avoid an unchecked warning?()ARemove line 14.BReplace line 14 with "int i = iter.next();".CReplace line 13 with "for (int i : intList) {".

题目
多选题
Given a pre-generics implementation of a method: What three changes allow the class to be used with generics and avoid an unchecked warning?()
A

Remove line 14.

B

Replace line 14 with "int i = iter.next();".

C

Replace line 13 with "for (int i : intList) {".

D

Replace line 13 with "for (Iterator iter : intList) {".

E

Replace the method declaration with "sum(List  intList)".

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

第1题:

11. public static void main(String[] args) {  12. Object obj =new int[] { 1,2,3 };  13. int[] someArray = (int[])obj;  14. for (int i: someArray) System.out.print(i +“ “)  15. }  What is the result? ()

  • A、 1 2 3
  • B、 Compilation fails because of an error in line 12.
  • C、 Compilation fails because of an error in line 13.
  • D、 Compilation fails because of an error in line 14.
  • E、 A ClassCastException is thrown at runtime.

正确答案:A

第2题:

1. public class Target {  2. private int i = 0;  3. public int addOne() {  4. return ++i;  5. }  6. }  And:  1. public class Client {  2. public static void main(String[] args) {  3. System.out.println(new Target().addOne());  4. }  5. }  Which change can you make to Target without affecting Client?() 

  • A、 Line 4 of class Target can be changed to return i++;
  • B、 Line 2 of class Target can be changed to private int i = 1;
  • C、 Line 3 of class Target can be changed to private int addOne() {
  • D、 Line 2 of class Target can be changed to private Integer i = 0;

正确答案:D

第3题:

public static void main(String[]args){12.Object obj=new int[]{1,2,3};13.int[] someArray=(int[])obj;14.for(inti:someArray)System.out.print(i+"")15.}What is the result?()

A.123

B.Compilation fails because of an error in line 12.

C.Compilation fails because of an error in line 13.

D.Compilation fails because of an error in line 14.

E.A ClassCastException is thrown at runtime.


参考答案:A

第4题:

package foo;  import java.util.Vector; private class MyVector extends Vector {  int i = 1;  public MyVector() {  i = 2; } }  public class MyNewVector extends MyVector {  public MyNewVector() {  i = 4;  }  public static void main(String args[]) {  MyVector v = new MyNewVector();  }  }  What is the result?()

  • A、 Compilation succeeds.
  • B、 Compilation fails because of an error at line 5.
  • C、 Compilation fails because of an error at line 6.
  • D、 Compilation fails because of an error at line 14.
  • E、 Compilation fails because of an error at line 17.

正确答案:B

第5题:

1. class Super {  2. private int a;  3. protected Super(int a) { this.a = a; }  4. }  .....  11. class Sub extends Super {  12. public Sub(int a) { super(a); }  13. public Sub() { this.a= 5; }  14. }  Which two, independently, will allow Sub to compile?()

  • A、 Change line 2 to: public int a;
  • B、 Change line 2 to: protected int a;
  • C、 Change line 13 to: public Sub() { this(5); }
  • D、 Change line 13 to: public Sub() { super(5); }
  • E、 Change line 13 to: public Sub() { super(a); }

正确答案:C,D

第6题:

public class test (    public static void main (String args) {    int i = 0xFFFFFFF1;  int j = ~i;   }    )   What is the decimal value of j at line 5?()

  • A、 0
  • B、 1
  • C、 14
  • D、 –15
  • E、 An error at line 3 causes compilation to fail.
  • F、 An error at line 4 causes compilation to fail.

正确答案:D

第7题:

class Super {  public int getLenght( ) { return 4; }  }  public class Sub extends Super {  public long getLenght( ) { return 5; }  public static void main(String[] args) {  Super sooper = new Super( );  Sub sub = new Sub( );  System.out.println(  sooper.getLenght( ) + “,” + sub.getLenght( ) );  }  } What is the output?()

  • A、 Just after line 13.
  • B、 Just after line 14.
  • C、 Just after line 15.
  • D、 Just after line 16 (that is, as the method returns).

正确答案:C

第8题:

Given:11.publicvoidgenNumbers(){12.ArrayListnumbers=newArrayList();13.for(inti=0;i<10;i++){14.intvalue=i*((int)Math.random());15.IntegerintObj=newInteger(value);16.numbers.add(intObj);17.}18.System.out.println(numbers);19.}WhichlineofcodemarkstheearliestpointthatanobjectreferencedbyintObjbecomesacandidateforgarbagecollection?()

A.Line19

B.TheobjectisNOTacandidateforgarbagecollection.

C.Line17

D.Line16

E.Line18


参考答案:A

第9题:

对于下列代码: 1) class Person {   2} public void printValue(int i, int j) {//... }     3} public void printValue(int i){//... }    4} }   5) public class Teacher extends Person { 6} public void printValue( ) {//... }     7} public void printValue(int i) {//...}     8} public static void main(String args[]){     9} Person t = new Teacher( );     10} t.printValue(10);     11} } 第10行语句将调用哪行语句?()

  • A、 line 2
  • B、 line 3
  • C、 line 6
  • D、 line 7

正确答案:D

第10题:

1.public class test (  2.public static void main (String args[])    {  3.int  i = 0xFFFFFFF1;  4.int  j = ~i;  5.    6.}  7.)    What is the decimal value of j at line 5?()  

  • A、 0
  • B、 1
  • C、 14
  • D、 –15
  • E、 An error at line 3 causes compilation to fail.
  • F、 An error at line 4 causes compilation to fail.

正确答案:C

更多相关问题