java 100 基础题_java最最基础的题目(满分100分,笔试,不可上机):

呢?

7.下边的结果是:

public class Test{

public static Collection getSort(){

Collection sort = new LinkedList();

sort.add("B");

sort.add("C");

sort.add("A");

return sort;

}

public static void main(String[] args) {

for(Object o:getSort()){

System.out.println(o);

}

}

} 8.下边代码的结果是:

public class Test{

public static void foo(Listl ){

}

public static void main(String[] args) {

Listl1 = new ArrayList();

foo(l1);

ArrayListl2 = new ArrayList();

foo(l2);

ArrayList l3 = new ArrayList();

foo(l3);

ArrayListl4 = new ArrayList();

foo(l4);

}

} 9.下边代码的结果是:

public class Test{

public static Object get0(List l){

return l.get(0);

}

public static void main(String[] args) {

String o1 = get0(new LinkedList());

Object o2 = get0(new LinkedList());

Object o3 = get0(new LinkedList());

Object o4 = get0(new LinkedList>());

String o5 = (String)get0(new LinkedList());

}

}

10.

public class Test{

enum Example{

ONE,TWO,THREE;

}

public static void main(String[] args) {

Collection c = new ArrayList();

c.add(Example.THREE);

c.add(Example.THREE);

c.add(Example.THREE);

c.add(Example.TWO);

c.add(Example.TWO);

c.add(Example.ONE);

Set set = new HashSet(c);

}

} 对这句

Set set = new HashSet(c)

代码描述正确的是:

A.The set variable contains all six elements from the coll collection, and the order is guaranteed to be preserved.

B. The set variable contains only three elements from the coll collection, and the order is guaranteed to be preserved.

C. The set variable contains all six elements from the coll collection, but the order is NOT guaranteed to be preserved. D. The set variable contains only three elements from the coll collection, but the order is NOT guaranteed to be preserved.

11.以下程序哪些句子可以1,2的输出结果?

public class Test{

public static void main(String[] args) {

//Setset = new TreeSet();

//Setset = new HashSet();

Setset = new LinkedHashSet();

set.add(2);

set.add(1);

System.out.println(set);

}

} 12.