现有: 3. import java.util.*; 4. class ForInTest { 5.static List list=new ArrayList(); 6. 7.public static void main (String [] args) { 8.list. add("a"); list. add("b");list. add( "c"); 9. //insert code here 10. System.out.print (o); 11. } 12. } 哪一行插入到第9行将导致输出“abc"?() A、 for (Iterator o : list.iterator(); o.hasNext (); )B、 for (Iterator 0 : list)C、 for (Object o : list.iterator())D、 for (Object o : list)
现有: 3. import java.util.*; 4. class ForInTest { 5.static List list=new ArrayList(); 6. 7.public static void main (String [] args) { 8.list. add("a"); list. add("b");list. add( "c"); 9. //insert code here 10. System.out.print (o); 11. } 12. } 哪一行插入到第9行将导致输出“abc"?()
- A、 for (Iterator o : list.iterator(); o.hasNext (); )
- B、 for (Iterator 0 : list)
- C、 for (Object o : list.iterator())
- D、 for (Object o : list)
相关考题:
现有: 3.import java.util.*; 4.class ForInTest { 5.static List list = new ArrayList(); 6.public static void main (String [] args){ 7. 8.list.add("a"); list.add("b"); list.add("c"); 9.//insert code here 10.System.out.print(o); } } 哪一行插入到第9行将导致输出“abc”?() A、 for(Object o : list)B、 for(Iterator o : list)C、 for(Object o : list.iterator())D、 for(Iterator o : list.iterator(); o.hasNext (); )
import java.util.*; public class LetterASort { public static void main(String[] args) { ArrayList strings = new ArrayList(); strings.add(‟aAaA”); strings.add(”AaA”); strings.add(‟aAa”); strings.add(”AAaa”); Collections.sort(strings); for (String s: strings) { System.out.print(s + “ “); } } } What is the result?() A、 Compilation fails.B、 aAaA aAa AAaa AaAC、 AAaa AaA aAa aAaAD、 AaA AAaa aAaA aAaE、 aAa AaA aAaA AAaaF、 An exception is thrown at runtime.
现有: 1. class Propeller2 { 2. pulolic static void main (String[]args)//add code here? 3. { new Propeller2().topGo(); } 4. 5.void topGo() //add code here? 6. { middleGo(); } 7. 8.void middleGo() //add code here? 9. { go(); System.out.println ("late middle"); } void go() //add code here? 12. {throw new Exception(); } 13. } 为使代码通过编译,需要在哪一行加入声明throws Exception?() A、只在第11行B、在第8行和第11行C、在第5行、第8行和第11行D、在第2行、第5行、第8行和第11行
1. class Pizza { 2. java.util.ArrayList toppings; 3. public final void addTopping(String topping) { 4. toppings.add(topping); 5. } 6. } 7. public class PepperoniPizza extends Pizza { 8. public void addTopping(String topping) { 9. System.out.println(”Cannot add Toppings”); 10. } 11. public static void main(String[] args) { 12. Pizza pizza = new PepperoniPizza(); 13. pizza.addTopping(”Mushrooms”); 14. } 15. } What is the result?() A、 Compilation fails.B、 Cannot add ToppingsC、 The code runs with no output.D、 A NullPointerException is thrown in Line 4.
1. import java.util.*; 2. class ForInTest { 3. static List list = new ArrayList(); 4. 5. static List getList() { return list; } 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. // insert code here 10. System.out.print(o); 11. } 12. } 第 9 行插入哪一项将输出 abc?() A、for(char o: list)B、for(Object o: getList())C、for(Object o: getList();)D、for(Object o: o.getList())
现有: import java.util.*; class AddStuff2 { public static void main(String [] args) { TreeSett=new TreeSet(); if (t.add("one")) if (t.add("two")) if (t.add ("three")) add("four"); for (String s : t) System.out.print (s); } } 结果为:() A、 oneB、 one three twoC、 one two threeD、 one two three fourE、 four one three twoF、编译失败
现有: 1. import java.util.*; 2. class ForInTest { 3.static List list - new ArrayList(): 4. 5.static List getList() { return list; } 6. 7.public static void main (Strincj[] args) { 8.list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print (o); 11. } 12. } 第9行插入哪一项将输出abc?() A、 for(char o: list)B、 for (Object o: o.getList())C、 for(Object o: getList();)D、 for(Object o: getList())E、 for(Object o: o.getList();)
现有 public class Demo{ public static void main (String[] args){ List al=new ArrayList(); a1.add("l"); a1.add("2"); a1.add("2"); a1.add("3"); System.out.println (al); } } 上述程序执行后的输出是哪项?() A、 [1,2,3]B、 [1,2,3,3]C、 [1,2,2,3]D、 [2,1,3,2]
import java.util.*; public class NameList { private List names = new ArrayList(); public synchronized void add(String name) { names.add(name); } public synchronized void printAll() { for (int i = 0; i System.out.print(names.get(i) +“ “); } } public static void main(String[] args) { final NameList sl = new NameList(); for(int i=0;i2;i++) { new Thread() { public void ruin() { sl.add(”A”); sl.add(”B”); sl.add(”C”); sl.printAll(); } }.start(); } } } Which two statements are true if this class is compiled and run?() A、 An exception may be thrown at runtime.B、 The code may run with no output, without exiting.C、The code may rum with output “A B A B C C “, then exit.D、The code may ruin with output “A A A B C A B C C “, then exit.E、 The code may rum with output “A B C A B C A B C “, then exit.F、The code may ruin with output “A B C A A B C A B C “, then exit.
public static Iterator reverse(List list) { Collections.reverse(list); return list.iterator(); } public static void main(String[] args) { List list = new ArrayList(); list.add(” 1”); list.add(”2”); list.add(”3”); for (Object obj: reverse(list)) System.out.print(obj + “,”); } What is the result?() A、 3,2,1,B、 1,2,3,C、 Compilation fails.D、 The code runs with no output.E、 An exception is thrown at runtime.
1. import java.util.*; 2. public class Example { 3. public static void main(String[] args) { 4. // insert code here 5. set.add(new integer(2)); 6. set.add(new integer(l)); 7. System.out.println(set); 8. } 9. } Which code, inserted at line 4, guarantees that this program will output [1,2]? ()A、 Set set = new TreeSet();B、 Set set = new HashSet();C、 Set set = new SortedSet();D、 List set = new SortedList();E、 Set set = new LinkedHashSet();
现有: 1. import java.util.*; 2. 3. Class FindStuff { 4.public static void main (String[]args) { 5, //insert code here 6. c.put ("X", 123); 7. } 8. } 分别插入到第5行,哪三行允许代码编译?() A、 Map c= new SortedMap();B、 HashMap c= new HashMap();C、 HashMap c= new Hashtalole();D、 SortedMap c= new TreeMap();E、 ArrayList c= new ArrayList();F、 MaD c = new LinkedHashMap();
1. import java.util.*; 2. public class Test { 3. public static void main(String[] args) { 4. List strings = new ArrayList(); 5. // insert code here 6. } 7. } Which four, inserted at line 5, will allow compilation to succeed?()A、 String s = strings.get(0);B、 Iterator i1 = strings.iterator();C、 String[] array1 = strings.toArray();D、 Iterator i2 = strings.iterator();E、 String[] array2 = strings.toArray(new String[1]);F、 Iterator i3 = strings.iterator();
3. import java.util.*; 4. class ForInTest { 5. static List list = new ArrayList(); 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print(o); 11. } 12. } 哪一行插入到第9行将导致输出“abc”?() A、 for(Object o : list)B、 for(Iterator o : list)C、 for(Object o : list.iterator())D、 for(Iterator o : list.iterator(); o.hasNext (); )
现有: 3. import java.util.*; 4. class ForInTest { 5. static List list = new ArrayList(); 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print(o); 11. } 12. } 哪一行插入到第9行将导致输出“abc”?() A、 for(Object o : list)B、 for(Iterator o : list)C、 for(Object o : list.iterator())D、 for(Iterator o : list.iterator(); o.hasNext (); )
多选题1. import java.util.*; 2. public class Test { 3. public static void main(String[] args) { 4. List strings = new ArrayList(); 5. // insert code here 6. } 7. } Which four, inserted at line 5, will allow compilation to succeed?()AString s = strings.get(0);BIterator i1 = strings.iterator();CString[] array1 = strings.toArray();DIterator i2 = strings.iterator();EString[] array2 = strings.toArray(new String[1]);FIterator i3 = strings.iterator();
多选题import java.util.*; public class NameList { private List names = new ArrayList(); public synchronized void add(String name) { names.add(name); } public synchronized void printAll() { for (int i = 0; i System.out.print(names.get(i) +“ “); } } public static void main(String[] args) { final NameList sl = new NameList(); for(int i=0;iAAn exception may be thrown at runtime.BThe code may run with no output, without exiting.CThe code may rum with output “A B A B C C “, then exit.DThe code may ruin with output “A A A B C A B C C “, then exit.EThe code may rum with output “A B C A B C A B C “, then exit.FThe code may ruin with output “A B C A A B C A B C “, then exit.
单选题public static Iterator reverse(List list) { Collections.reverse(list); return list.iterator(); } public static void main(String[] args) { List list = new ArrayList(); list.add(” 1”); list.add(”2”); list.add(”3”); for (Object obj: reverse(list)) System.out.print(obj + “,”); } What is the result?()A 3,2,1,B 1,2,3,C Compilation fails.D The code runs with no output.E An exception is thrown at runtime.
单选题1. import java.util.*; 2. public class Example { 3. public static void main(String[] args) { 4. // insert code here 5. set.add(new integer(2)); 6. set.add(new integer(l)); 7. System.out.println(set); 8. } 9. } Which code, inserted at line 4, guarantees that this program will output [1,2]? ()A Set set = new TreeSet();B Set set = new HashSet();C Set set = new SortedSet();D List set = new SortedList();E Set set = new LinkedHashSet();
单选题现有: 3. import java.util.*; 4. class ForInTest { 5. static List list = new ArrayList(); 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. //insert code here 10. System.out.print(o); 11. } 12. } 哪一行插入到第9行将导致输出“abc”?()A for(Object o : list)B for(Iterator o : list)C for(Object o : list.iterator())D for(Iterator o : list.iterator(); o.hasNext (); )
单选题1. import java.util.*; 2. class ForInTest { 3. static List list = new ArrayList(); 4. 5. static List getList() { return list; } 6. 7. public static void main(String [] args) { 8. list.add("a"); list.add("b"); list.add("c"); 9. // insert code here 10. System.out.print(o); 11. } 12. } 第 9 行插入哪一项将输出 abc?()Afor(char o: list)Bfor(Object o: getList())Cfor(Object o: getList();)Dfor(Object o: o.getList())
单选题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只有s1B只有s3C只有s1和s3D只有s1和s4
单选题import java.util.*; public class LetterASort { public static void main(String[] args) { ArrayList strings = new ArrayList(); strings.add(‟aAaA”); strings.add(”AaA”); strings.add(‟aAa”); strings.add(”AAaa”); Collections.sort(strings); for (String s: strings) { System.out.print(s + “ “); } } } What is the result?()A Compilation fails.B aAaA aAa AAaa AaAC AAaa AaA aAa aAaAD AaA AAaa aAaA aAaE aAa AaA aAaA AAaaF An exception is thrown at runtime.
多选题现有: 1. import java.util.*; 2. 3. Class FindStuff { 4.public static void main (String[]args) { 5, //insert code here 6. c.put ("X", 123); 7. } 8. } 分别插入到第5行,哪三行允许代码编译?()AMap c= new SortedMap();BHashMap c= new HashMap();CHashMap c= new Hashtalole();DSortedMap c= new TreeMap();EArrayList c= new ArrayList();FMaD c = new LinkedHashMap();
单选题现有: 1. class Propeller2 { 2. pulolic static void main (String[]args)//add code here? 3. { new Propeller2().topGo(); } 4. 5.void topGo() //add code here? 6. { middleGo(); } 7. 8.void middleGo() //add code here? 9. { go(); System.out.println ("late middle"); } void go() //add code here? 12. {throw new Exception(); } 13. } 为使代码通过编译,需要在哪一行加入声明throws Exception?()A只在第11行B在第8行和第11行C在第5行、第8行和第11行D在第2行、第5行、第8行和第11行
单选题现有: 3.import java.util.*; 4.class ForInTest { 5.static List list = new ArrayList(); 6.public static void main (String [] args){ 7. 8.list.add("a"); list.add("b"); list.add("c"); 9.//insert code here 10.System.out.print(o); } } 哪一行插入到第9行将导致输出“abc”?()A for(Object o : list)B for(Iterator o : list)C for(Object o : list.iterator())D for(Iterator o : list.iterator(); o.hasNext (); )
单选题现有: import java.util.*; class AddStuff2 { public static void main(String [] args) { TreeSett=new TreeSet(); if (t.add("one")) if (t.add("two")) if (t.add ("three")) add("four"); for (String s : t) System.out.print (s); } } 结果为:()A oneB one three twoC one two threeD one two three fourE four one three twoF编译失败