Java基础强化练习题2

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1. 下列代码的输出结果是:(A)

public class Yikes {

public static void go(Long n) {

System.out.println("Long ");

}

public static void go(Short n) {

System.out.println("Short ");

}

public static void go(int n) {

System.out.println("int ");

}

public static void main(String[] args) {

short y = 6;

long z = 7;

go(y);

go(z);

}

}

A.

Long

Long

B.

Short

Long

C.

int

Long

D.

int

int

2. 下面不属于接口的是:(D)。

A. java.sql.Connection

B. java.sql.Driver

C. java.sql.DriverManager

D. java.sql.ResultSet

3. synchronized关键字做同步,可以使用在:(A)。

A. 方法上

B. 接口上

C. 变量上

D. 类上

4. 类A的定义如下:

class A {

protected void f() throws FileNotFoundException { ………

}

}

下列代码段没有编译错误的是:(A)。

A.

class B extends A {

public void f() throws Exception {

………

}

}

B.

class B extends A {

public void g() throws IOException {

f();

}

}

C.

class B extends A {

public void g() {

try{

f();

………

}

catch(IOException e) {

………

}

catch(FileNotFoundException e1) {

………

}

}

}

D.

class B extends A {

public void g() {

try {

f();

}

catch(FileNotFoundException e) {

throw new RuntimeException(e);

}

}

}

5. 下列选项中能够得到字符串的一部分的单行函数是()。

A. INSERT

B. SUBSTR

C. LPAD

D. LEAST

6. ResultSet提供了获取数据库中某个字段值的方法,如果某个字段为NUMBER类型,可以获取该字段值的方法是:(A )。

A. getNumber()

B. getDouble()

C. setNumber()

D. setDouble()

7. 下列代码编译和运行的结果是(A)

public class A {

void process() throws Exception {

throw new Exception();

}

public static void main(String[] args) {

A a = new B();

a.process();

}

}

class B extends A {

void process() {

System.out.println("B ");

}

}

A. 输出:B

B. 无输出

C. B类的process方法处,出现编译错误

D. 代码a.process();行,出现编译错误

8. 下列代码编译和运行的结果是:(A)

public static void main(String[] args) {

Float pi = new Float(3.14f);

if (pi > 3) {

System.out.print("pi is bigger than 3. ");

} else {

System.out.print("pi is not bigger than 3. ");

}

finally { 不能单独使用

System.out.println("Have a nice day.");

}

}

A. 编译失败

B. 输出:pi is bigger than 3.

C. 输出:pi is bigger than 3. Have a nice day

D. 输出:pi is not bigger than 3. Have a nice day.

9. 需要读取一个比较大的文本文件,这个文件里有很多字节的数据,那么下列最合适读这个文件的选项是:(C)。

A. new FileInputStream(“fileName”);

B. new InputStreamReader(new FileInputStream(“fileName”));

C. new BufferedReader(new InputStreamReader(new FileInputStream(“fileName”)));

D. new RandomAccessFile(“fileName”,”+rw”);

10. 运行下列程序:

public static void main(String[] args) {

String str = "**oracle***oracle*****oracle***";

String str1 = "oracle";

int index = 0;

while ((index = str.indexOf(str1, index)) != -1) {

System.out.print(index + "");

index += str1.length();

}

}

控制台输出的结果是:()。

A. 1 10 21

B. 2 11 22

C. 3 13 23

D. 5 13 22

11. 运行下列代码,输出为false的是:(A)。

A. String st1 = "abc";

System.out.println("abc" == st1);

B. String st2 = "abc";

System.out.println(st2.equals(new String("abc")));

C. Integer i = 100;

System.out.println(100 == i);

D. ArrayList list = new ArrayList();

System.out.println(list.contains(null));

12. 下面关于ResultSet说法错误的是(D)。

A. 查询结束后,所有的结果数据将一次被存储在ResultSet对象中

B. Statement对象close后,由其创建的ResultSet对象将自动的close

C. 查询结束后,ResultSet中的游标指向第一条记录之上,因此要先调用一次next()才有可

相关文档
最新文档