单选题public static void search(List list) { list.clear(); list.add(”b”); list.add(”a”); list.add(”c”); System.out.println(Collections.binarySearch(list, “a”)); } What is the result of calling search with a valid List implementation?()A0B1CaDbEcFThe result is undefined.
单选题
public static void search(List list) { list.clear(); list.add(”b”); list.add(”a”); list.add(”c”); System.out.println(Collections.binarySearch(list, “a”)); } What is the result of calling search with a valid List implementation?()
A
0
B
1
C
a
D
b
E
c
F
The result is undefined.
参考解析
解析:
暂无解析
相关考题:
试题六(共 15分)阅读以下说明和Java代码,将应填入 (n) 处的字句写在答题纸的对应栏内。【说明】已知类 LinkedList 表示列表类,该类具有四个方法:addElement()、lastElement()、umberOfElement()以及removeLastElement()。四个方法的含义分别为:void addElement(Object): 在列表尾部添加一个对象;Object lastElement(): 返回列表尾部对象;int numberOfElement(): 返回列表中对象个数;void removeLastElement(): 删除列表尾部的对象。现需要借助LinkedList来实现一个Stack栈类, Java代码1和Java代码2分别采用继承和组合的方式实现。【Java代码1】public class Stack extends LinkedList{public void push(Object o){ //压栈addElement(o);}public Object peek(){ //获取栈顶元素return (1) ;}public boolean isEmpty(){ //判断栈是否为空return numberOfElement() == 0;}public Object pop(){ //弹栈Object o = lastElement();(2) ;return o;}}【Java代码2】public class Stack {private (3) ;public Stack(){list = new LinkedList();}public void push(Object o){list.addElement(o);}public Object peek(){//获取栈顶元素return list. (4) ;}public boolean isEmpty(){//判断栈是否为空return list.numberOfElement() == 0;}public Object pop(){ //弹栈Object o = list.lastElement();list.removeLastElement();return o;}}【问题】若类LinkedList新增加了一个公有的方法removeElement(int index),用于删除列表中第index个元素,则在用继承和组合两种实现栈类Stack的方式中,哪种方式下Stack对象可访问方法removeElement(int index)? (5) (A. 继承 B. 组合)
【Java代码】import Java.util.ArrayList;import java.util.List;(1) class AbstractFile{protected String name;public void printName(){System.out.println(name);}public abstract boolean addChild(AbstractFile file);public abstract boolean removeChild(AbstractF ile file);public abstract ListAbstractFile getChildren();}class File extends AbstractFile{public File(String name){this.name=name;}public boolean addChild(AbstractFile file){return false;}public boolean removeChild(AbstractFile file){return false;}public ListAbstractFile getChildren(){return (2) ;}}class Folder extends AbstractFile{private List AbslractFile childList;public Folder(String name){this.name=name;this.childList=new ArrayListAbstractFile();}public boolean addChild(AbstractFile file) { return childList.add(file);}public boolean removeChild(AbstractFile file){return childList.remove(file);}public (3) AbstractFile getChildren(){return (4) ;}}public class Client{public static void main(String[] args){//构造一个树形的文件/目录结构AbstractFile rootFolder= new Folder("c:\\ ");AbstractFile compositeFolder=new Folder("composite");AbstractFile windowsFolder=new Folder("windows");AbstractFile file=new File("TestComposite.java");rootFolder.addChild(compositeFolder) ;rootFolder.addChild(windowsFolder);compositeFolder.addChild(file) ;//打印目录文件树printTree(rootFolder);}private static void printTree(AbslractFile ifile){ifile.printName();List AbslractFile children=ifile.getChildreno:if(children==null) return;for (AbstractFile file:children) {(5) ;}}}该程序运行后输出结果为:c:\compositeTestComposite.javaWindows
publicstaticvoidsearch(Listlist){list.clear();list.add(”b”);list.add(”a”);list.add(”c”);System.out.println(Collections.binarySearch(list,a”));}WhatistheresultofcallingsearchwithavalidListimplementation?()A.0B.1C.aD.bE.cF.Theresultisundefined.
阅读以下说明和c++代码,将应填入(n)处的字句写在对应栏内。【说明】本程序将两个从小到大的有序链表合成一个新的从小到大的有序链表。链表的每一项由类 Node描述,而链表由List描述,类List的成员函数有以下几个:creatList(): 创建从小到大的有序链表。multiplyList(List L1, Llst L2): 将链表L1和链表L2合并。print(): 打印链表。【C++代码】include <iostream>using namespace std;class List;class Node{friend class List;public:Node(int data){(1);}private:int data;Node *next;};class List{public:List(){list=NULL;}void multiplyList(List L1, List L2);void creatList();void print();private:Node *list;};void List::creatList(){Node *p, *u, *pre;int dara;list=NULL;wbile(1){cout<<"输入链表的一项: (小于零,结束链表) "<<endl;cin>>data;if(dara<0)break;//小于零,结束输入p=list;while(p !=NULL dara>p->data){//查找插入点pre=p;p=p->next;}u=(2);if(p==list)list=u;else pre->next=u;(3);}}void List::multiplyList(List L1, List L2){Node *pL1, *pL2, *pL, *u;list = NULL;pL1 = L1.list;pL2 = L2.11st;while(pL1 != NULL pL2 != NULL){if(pL1->data < pL2->data){u = new Node(pL1->data);pL1 = pL1->next;}else{u = new Node(pL2->data);pL2 = pL2->next;}if(list == NULL){list =(4);}else{pL->next=u;pL=u;}}pL1 = (pL1 != NULL)? pL1:pL2;while(pL1 != NULL){u=(5);pL1 = pL1->next;if(list == NULL){list=pL=u;}else{pL->next=u;pL=u;}}}void List::print(){Node *p;p = list;while(p !=NULL){cout<<p->data<<"\t";p=p->next;&
以下哪个是Java应用程序main方法的有效定义? A. public static void main();B. public static void main( String args );C. public static void main( String args[] );D. public static void main( Graphics g );E. public static boolean main( String a[] );
( ) is a list of items that are accessible at only one end of the list. A. AtreeB. An arrayC. A stackD. Aqueue
以下是JAVA中正确的入口方法是? () A、 public static void main(String[] args){}B、 public static void main(String args){}C、 public void main(String[] args){}D、 public static int main(String[] args){}
现有: 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 (); )
11. public void addStrings(List list) { 12. list.add(”foo”); 13. list.add(”bar”); 14. } What must you change in this method to compile without warnings?() A、 add this code after line 11: list = (List) list;B、 change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);C、 change the method signature on line 11 to: public void addStrings(List extends String list) {D、 change the method signature on line 11 to: public void addStrings(List super String list) {E、 No changes are necessary. This method compiles without warnings.
Which declarations will allow a class to be started as a standalone program?() A、public void main(String args[])B、public void static main(String args[])C、public static main(String[] argv)D、final public static void main(String [] array)E、public static void main(String args[])
public class Alpha{ private static Character() ids; public static void main( String[] args){ ids = new Character[args.length]; for (int i=0; iids[i] = new Character( args[i] ); System.out.print( ids[i] ); } } } What is correct?() A、 Compilation fails.B、 The code runs with no output.C、 An exception is thrown at runtime.D、 The code runs, outputing a concatenated list of the arguments passed to the program.
public static void search(List list) { list.clear(); list.add(”b”); list.add(”a”); list.add(”c”); System.out.println(Collections.binarySearch(list, “a”)); } What is the result of calling search with a valid List implementation?()A、0B、1C、aD、bE、cF、The result is undefined.
下列有关main()方法的签名正确的是哪些?()A、 public static void main(String[] args){}B、 public static void main(){}C、 public static void main(String args[]){}D、 public void static main(String[] args){}
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())
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.
11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List intList = new ArrayList(); 14. append(intList); 15. System.out.println(intList.get(0)); 16. } What is the result?() A、 42B、 0042C、 An exception is thrown at runtime.D、 Compilation fails because of an error in line 13.E、 Compilation fails because of an error in line 14.
下面哪些main方法可用于程序执行()A、public static void main(String[]args)B、public static void main(String[]x)C、public static void main(Stringargs[])D、public void main(String[]args)
单选题11. public static void append(List list) { list.add(”0042”); } 12. public static void main(String[] args) { 13. List intList = new ArrayList(); 14. append(intList); 15. System.out.println(intList.get(0)); 16. } What is the result?()A 42B 0042C An exception is thrown at runtime.D Compilation fails because of an error in line 13.E Compilation fails because of an error in line 14.
单选题_____APrepare a price list.BGo to the Brown Company.CSend a parcel by post.DMail a price list.
单选题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.
单选题11. public void addStrings(List list) { 12. list.add(”foo”); 13. list.add(”bar”); 14. } What must you change in this method to compile without warnings?()A add this code after line 11: list = (List) list;B change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);C change the method signature on line 11 to: public void addStrings(List extends String list) {D change the method signature on line 11 to: public void addStrings(List super String list) {E No changes are necessary. This method compiles without warnings.
单选题现有: 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)
单选题10. interface A { void x(); } 11. class B implements A { public void x() { } public voidy() { } } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a:list) { 24. a.x(); 25. a.y();; 26. } What is the result?()A The code runs with no output.B An exception is thrown at runtime.C Compilation fails because of an error in line 20.D Compilation fails because of an error in line 21.E Compilation fails because of an error in line 23.F Compilation fails because of an error in line 25.
单选题现有: 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.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 (); )
单选题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())
单选题public class Alpha{ private static Character() ids; public static void main( String[] args){ ids = new Character[args.length]; for (int i=0; iids[i] = new Character( args[i] ); System.out.print( ids[i] ); } } } What is correct?()A Compilation fails.B The code runs with no output.C An exception is thrown at runtime.D The code runs, outputing a concatenated list of the arguments passed to the program.