一、选择题
1. 当我们定义变量时,下列哪个是错误的?( C ) A、_sys B 、$change C 、1name D、thisOne 2. 当我们定义类名,下列哪个是错误的?( B ) A、Employee B 、3G C 、helloworld D、Hello$World 3. 在Java中,整型int存储的字节长度为( C )
A、1 B、2 C、4 D、8
4. 查看下列代码,说法正确的是( B )。 byte b = 10; short s = 200; short c = b + s;
A、程序执行正确。 B、程序编译错误。
5. 当我们定义不同类型的变量时,哪个是错误的?( A )
A、byte b = 128 B、char a = 'a' C、double d = 1.3d D、float f = 3.1415f
6. MyClass类的默认构造器是( B )
A、new MyClass() B、MyClass(){} C、MyClass{} D、public class MyClass 7. 构造函数何时被调用?( A )
A、创建对象时 B、类定义时
C、使用对象的方法时 D、使用对象的属性时
8. 下列定义数组正确的是( ABD )选三项
A、String[] s1 = new String[4]; B、String[] s2 = {\ C、String[] s4 = String[4]; D、String s3[] = new String[4]; E、char[] s5 = {null};
9. 下面定义一个String值是正确的是( BCE )选三项
A、String a = I'm a String; B、String b = \ C、String c = new String(); D、String d = 'I'm as String'; E、String e = new String(\a String\
10. 以下关于构造函数的描述错误的是( A )。 A、构造函数的返回类型只能是void型。
B、构造函数是类的一种特殊函数,它的方法名必须与类名相同。 C、构造函数的主要作用是完成对类的对象的初始化工作。 D、一般在创建新对象时,系统会自动调用构造函数。 11. 设有下面两个赋值语句:
a = Integer.parseInt(“12”); b = Integer.valueOf(“12”).intValue(); 下述说法正确的是( D )。 A、a是整数类型变量,b是整数类对象。 B、a是整数类对象,b是整数类型变量。 C、a和b都是整数类对象并且值相等。 D、a和b都是整数类型变量并且值相等。 12. 在Java中,一个类可同时定义许多同名的方法,这些方法的形式参数个数、类型或顺
序各不相 同,传回的值也可以不相同。这种面向对象程序的特性称为( C )。 A、隐藏 B、覆盖 C、重载 D、Java不支持此特性
13. 下列X,Y,和Z都是接口。下列正确的接口声明是什么( AC )。选二项 A、public interface A extends X{void aMethod();} B、interface B implements Y {void aMethod();}
C、interface C extends X,Y,Z {void aMethod();} D、interface C extends X {protected void aMethod();} 14. 以下关于继承的叙述正确的是( A )。 A、在Java中类只允许单一继承
B、在Java中一个类只能实现一个接口
C、在Java中一个类不能同时继承一个类和实现一个接口 D、在Java中接口只允许单一继承
15. 给出下面代码,关于该程序以下哪个说法是正确的?( A ) public class Person{ int arr[] = new int[5];
public static void main(String a[]) {
System.out.println(arr[0]); } } A、编译时将产生错误 B、编译时正确,运行时出错 C、输出零 D、输出空
16. 下列抽象类定义正确的是哪个?( C ) A、class MyClass { abstract void hello();} B、abstract Myclass { abstract void hello();} C、abstract class MyClass { abstract void hello();} D、abstract class MyClass { abstract void hello({System.out.println(\17. 查看下面的程序LoginApp.java class User{ private String name; private String pwd; private User(){ } }
public class LoginApp{ public static void main(String[] args){ User user = new User(); } }
以下说法正确的是( A )。 A、程序不能正确编译。 B、程序能正确编译,user是已实例化的对象。 C、程序能正确编译,user不能被实例化对象。 D、程序能正确编译。 18. 查看下列代码 public class MyClass{ private String loginName;
public static void main(String[] args) { System.out.println(this.loginName); } }
以下说法正确的是( A )。 A、程序不能正确编译。 B、程序能正确编译,打印loginName的内容。 C、程序能正确编译,不能打印loginName,因为loginName没有给初始值。 D、程序能正确编译。
19. 下列哪些是正确的( ABC )。选三项 A、private final String loginName = \ B、final int i = 0; C、static final String s = \ D、const final int m = 0; E、private final String name; 20. 下列说法正确的有( C ) A、class中的constructor不可省略。 B、 constructor必须与class同名,但方法不能与class同名。 C、 constructor在一个对象被new时执行。 D、一个class只能定义一个constructor。
21. 下面哪个流类属于面向字符的输入流( D )。 A、BufferedWriter B、FileInputStream C、ObjectInputStream D 、InputStreamReader
22. Java接口的修饰符可以为( CD )。选二项 A、private B、 protected C、 final D、 abstract 23. 当我们新建一个流对象,下面哪个选项的代码是错误的?( B ) A、new BufferedWriter(new FileWriter(\ B、new BufferedReader(new FileInputStream(\ C、new GZIPOutputStream(new FileOutputStream(\ D、new ObjectInputStream(new FileInputStream(\24. 查看下列代码: public class foo{
public static void main (String[] args){ String s1;
System.out.println(\ } }
下列哪个说法是正确的( C )。 A、 代码得到编译,并输出“s=”。 B、 代码得到编译,并输出“s=null”。
C、 由于String s没有初始化,代码不能编译通过。
D、 代码得到编译,但捕获到 NullPointException异常。
25. 下列哪种异常是检查型异常,需要在编写程序时声明 ( C ) A、NullPointerException B、ClassCastException
C、FileNotFoundException D 、IndexOutOfBoundsException
26. 选项中哪一行代码可以替换题目中//add code here而不产生编译错误?( A ) 查看下列代码:
public abstract class MyClass { public int constInt = 5; //add code here
public void method() { } }
A、public abstract void method(int a); B、 constInt = constInt + 5; C、 public int method();
D、 public abstract void anotherMethod() {}
27. importCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中
产生了一个IOException,将会输出什么结果( )。 查看下列代码:
public void importCustomerInfo() { try {
// do something that may cause an Exception } catch (java.io.FileNotFoundException ex) {
System.out.print(\ } catch (java.io.IOException ex) {
System.out.print(\ } catch (java.lang.Exception ex) { System.out.print(\ } }
哪个是正确的输出( A )。 A、IOException!
B、IOException!Exception!
C、FileNotFoundException!IOException!
D、FileNotFoundException!IOException!Exception! 28. 关于异常处理机制的叙述哪些正确( BC )。
A、catch部分捕捉到异常情况时,才会执行finally部分。
B、当try区段的程序发生异常时,才会执行catch区段的程序。
C、不论程序是否发生错误及捕捉到异常情况,都会执行finally部分。 D、以上都是。
29. 在Java Applet程序用户自定义的Applet子类中,一般需要重载父类的( D )方法
来完成一些画图操作。
A、start( ) B、stop( ) C、init( ) D、paint( )
30. 下面哪些是Thread类的方法( ABD )。选三项
A 、start() B、 run() C、 exit() D、 getPriority()
二、代码阅读题
1. 阅读下列代码,请写出它的运行输出结果: 程序:
public class TestOper{ public static void main(String[] args){ int i = 0; System.out.println(\ System.out.println(\ i = 0; System.out.println(\ } }
结果: i=0;(i++)=0 i=1
i=0;(++i)=1
2. 阅读下列程序,请写出运行结果并说明原因。 String str1 = \
String str2 = \System.err.println(str1 == str2); 结果: false,
因为str2中的llo是新申请的内存块,而==判断的是对象的地址而非值,所以不一样。 3. 阅读下列程序,请写出运行结果。 当i输入值为2时。
public static int getValue(int i) { int result = 0; switch (i) { case 1:
result = result + i; case 2:
result = result + i * 2; case 3:
result = result + i * 3; }
return result; } 结果:10
4. 阅读下列程序,请写出运行结果。 class HelloA {
public HelloA() {