一.单选题(20分)
1.下面哪些不是JAVA的基本数据类型 ( C )
A、long B、float C、String D、double
2.表达式“5 / 2”的结果:( A )
A.2
B.2.5
C.2.555555
D.3
3.下面程序运行的结果是:( A )
public class X {
private static int a;
public static void main(String [] args) {
modify(a);
System.out.println(a);
}
public static void modify(int a) {
a++;
}
}
A.0
B.1
C.程序编译失败
D.程序运行抛出异常
4.下面都属于线程安全的类是:(B D)
A.ArrayList
B.Vector
C.HashMap
D.Hashtable
5.根据代码选择输出结果:( C)
public class Ob {
private static int a = 0;
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
a += i;
new Thread(new Runnable() {
public void run() {
System.out.print(a + " ");
}
}).start();
}
}
}
A.0 1 2 3 4
B.1 2 3 4 5
C.不确定
D.5 4 3 2 1
6.根据代码选择输出结果:(B )
int i = 0, j = 1;
if ((i++ == 1) && (j++ == 2)) {
i = 42;
}
System.out.println("i = " + i + ", j = " + j);
A.i=1,j=2
B.i=1,j=1
C.i=42,j=2
D.i=42,j=1
7.下面程序运行的结果是:( A )
import java.io.IOException;
public class ExceptionTest{
public static void main (String[]args) {
try {
methodA();
}catch (IOException e) {
System.out.println(“Caught IOException”);
} catch (Exception e) {
System.out.println(“Caught Exception”);
}
}
public void methodA () {
throw new IOException ();
}
}
A.程序编译失败
B.程序输出Caught Exception
C.程序输出Caught IOException
D.程序无输出结果
8.根据代码选择输出结果:( D )
class A {
protected String s = “A”;
protected void method() {
System.out.println(s);
}
}
class B extends A {
protected String s = “B”;
protected void method() {
System.out.println(s);
}
}
class C extends B {
protected String s = “C”;
}
class D extends C {
protected String s = “D”;
}
public class Ob {
public static void main(String[] args) {
A a = new B();
a.method();D
B b = new C();
System.out.println(b.s);
C c = new D();
c.method();
D d = new D();
System.out.println(d.s);
}
}
A.A B C D
B.B C D D
C.B C D B
D.B B B D
9.根据代码选择输出结果:(B )
class A {
static {
System.out.print("static A ");
}
public A() {
System.out.print("A ");
}
}
class B extends A {
static {
System.out.print("static B ");
}
public B() {
System.out.print("B ");
}
}
class C extends B {
static {
System.out.print("static C ");
}
public C() {
System.out.print("C ");
}
}
public class Ob {
public static void main(String[] args) {
new C();
}
}
A.static C C static B B static A A
B.static A static B static C A B C
C.A B C static A static B static C
D.C B A static C static B static A
10.以下代码的输出结果为 ( C )
int i = 3;
int x = (i++)+(++i)+(i++);//3+5+5
System.out.println(x);
A.9
B.11
C.13
D.15
二.多选题(20分)
1.(多选题)请看下列代码:AC
public class Old {
public static Object get(List list) {
return list.get(0);
}
}
以下选项调用get方法,能编译通过的是:
A. Object o = Old.get(new LinkedList());
B. Object o = Old.get(new LinkedList>());
C. String s = Old.get(new LinkedList());
D. String s = (String)Old.get(new LinkedList());
2.(多选题)下列选项中,对Object类描述正确的是(AB )。
A.Java中所有的类,都默认自动继承了Object类
B.Java中所有的类都从Object类中继承了toString()方法、
hashCode()方法和equals()等方法
C.Object类中toString()方法的返回值是一个字符串,
equals方法的返回值为1或0
D.定义类的时候,类中必须重写Object类中的toString(),equals(),hashCode()方法
3.(多选题)可以表示6位任意数字的正则是(AB )。
A.
5.(多选题)关于集合框架,说法正确的是(BD )。
A.与数组不同,集合框架是容量可变的容器
B.集合框架不能保存基本类型,但是可以将它们转换为包装类后保存
C.集合框架中的List, Set, Map接口都是Collection接口的子接口
D.集合类除了提供可变容量的存储外,还提供了对数据的算法
6.(多选题)String str = “We are students”; 下面说法正确的是(AC )。
A.str的长度是15
B.str的长度是14
C.str.indexOf(“a”)返回的结果是3
D.str.lastIndexOf(“e”)返回的结果是3
7.(多选题)下列逻辑表达式,值为false的是(BCD)。
A. “abc,bcd,def,efg,”.split("[,]+").length == 4;
B. “1st456”.matches("\d[a-z&&[^et]]{2,8}[0-9]+");
C. “abcdefghijklmnopqrstuvwxyz”.substring(5,26).length() == 20;
D. “whatisjava”.equals(null);
8.(多选题)在Java语言中,下列说法正确的是:(ABD)。
A.StringBuffer和StringBuilder的区别在于:StringBuffer是线程安全的而StringBuilder不是。
B.String是不可变对象,而StringBuffer中封装的字符串数据是可以动态改变的。
C.判断两个StringBuilder对象的字符序列是否相同,可以调用其equlas方法进行比较。
D.String的重写了equals方法,重写的逻辑是:字符序列相同的String对象equals方法返回true。
9.(多选题)题目代码的功能为:输出每个字符在一个字符串中出现的次数(不区分大小写)。
String str = “ewrwqFrewqfsadfdsfdsfs”;
str=str.toLowerCase();
int max_length = 0;
while (str.length() > 0) {
《插入代码》
}
A. int length = str.length();
char first=str.charAt(0);
String strNew = str.replaceAll(String.valueOf(first), “”);
if (length>strNew.length()) {
max_length = length - strNew.length();
System.out.println(first+":"+max_length);
}
B. int length = str.length();
char first=str.charAt(0);
String strNew = str.replaceAll(String.valueOf(first), “”);
if (length>strNew.length()) {
max_length = length - strNew.length();
str = strNew;
System.out.println(first+":"+max_length);
}
C. int length = str.length();
String first = str.substring(0, 1);
String strNew = str.replaceAll(first, “”);
if (length>strNew.length()) {
max_length = length - strNew.length();
str = strNew;
System.out.println(first+":"+max_length);
}
D. int length = str.length();
String first = str.substring(0, 1);
String strNew = str.replaceAll(first, “”);
if (length>strNew.length()) {
max_length = length - strNew.length();
System.out.println(first+":"+max_length);
}
10.(多选题)下列关于HashMap的描述正确的是:ABD
A.HashMap的Key和Value是以链表的方式存入对应的bucket
B.HashMap的查找方式是获取Key的hashCode值,通过hash算法确定存储的bucket,
调用equals方法依次与bucket中的Key进行比较
C.放入HashMap集合中的元素按照key的自然顺序排序
D.HashMap中的key是不可以的重复的
0-9 ↩︎
0~9 ↩︎