Java基础强化练习题2

更新时间:2023-09-18 12:11:01 阅读量: 幼儿教育 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

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

public class Yikes { public static void go(Long n) { System.out.println(\ } public static void go(Short n) { System.out.println(\ } public static void go(int n) { System.out.println(\ } 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. 方法上 B. 接口上 C. 变量上 D. 类上

A)。

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(\ } }

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(\ } else { System.out.print(\ } finally { 不能单独使用

System.out.println(\ } }

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 = \ String str1 = \ 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 = \

System.out.println(\ B. String st2 = \

System.out.println(st2.equals(new String(\ 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()才有可

能取得记录

D. ResultSet的的方法getString(...)意为取得该列的数据以字符串的形式返回,数据库中的该列类型并不一定必须是字符类型

13. 下列属于DML语句的是 :() 。

A. COMMIT B. INSERT C. DROP D. GRANT

14. 下面关于事务(Transaction)的说法错误的是:(D)。

A. 事务具备ACID四个基本特性,即A(Atomicity)—原子性、C(Consistency)—一致性、I(Isolation)—隔离性、D(Durability)—持久性。

B. 事务的提交(Commit)指将事务中所有对数据库的更新写到磁盘上的物理数据库中去,事务正常结束。

C. 事务的回滚(Rollback)指在事务运行的过程中发生了某种故障,事务不能继续进行,将事务中对数据库的所有以完成的操作全部撤消,回滚到事务开始的状态。 D. JDBC通过Connection对象控制事务,默认方式下,在执行完更改语句后需要必须要调用Connection的commit方法,对数据的更改才能生效。

15. 运行下面程序:

public class Foo { public static void main(String[] args) { try { test(); System.out.println(\ } catch (ArrayIndexOutOfBoundsException e) { System.out.println(\ } catch (Exception e) { System.out.println(\ } finally { System.out.println(\ } } public static void test() { String str = \ str.compareTo(\ } }

输出的结果是:(D)。 A. condition 1 finally B. condition 2 finally

C. condition 1 condition 3 finally D. condition 1 condition 2 finally

本文来源:https://www.bwwdw.com/article/v2ah.html

Top