Java基础强化练习题2(附答案)

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

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

正确答案:C

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

A. java.sql.Connection B. java.sql.Driver

C. java.sql.DriverManager D. java.sql.ResultSet 正确答案:C

3. synchronized关键字做同步,可以使用在:()。 A. 方法上 B. 接口上 C. 变量上 D. 类上

正确答案:A

4. 类A的定义如下:

class A {

protected void f() throws FileNotFoundException {

……… } }

下列代码段没有编译错误的是:()。 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); } } }

正确答案:D

分析:子类重写父类的方法时候不能声明抛出比父类大的异常

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

A. INSERT B. SUBSTR C. LPAD D. LEAST 正确答案:B

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

A. getNumber() B. getDouble() C. setNumber() D. setDouble() 正确答案:B

7. 下列代码编译和运行的结果是:

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();行,出现编译错误 正确答案:D

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

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. 正确答案:A

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

A. new FileInputStream(“fileName”);

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

C. new BufferedReader(new InputStreamReader(new FileInputStream(“fileName”))); D. new RandomAccessFile(“fileName”,”+rw”); 正确答案:C

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 正确答案:B

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

A. String st1 = \

System.out.println(\

联系客服:779662525#qq.com(#替换为@)