(单选题) 1: 已知如下代码: boolean m = true; if ( m = false ) System.out.println("False"); else System.out.println("True"); 执行结果是什么?
A: False
B: True
C: 编译时出错
D: 运行时出错
正确答案:
(单选题) 2: 有下面的类:public class Example{ static int x[]=new int[15]; public static void main(String args[]){ System.out.println(x[5]); } } 下面的那些说法是正确的。
A: 编译时出错
B: 运行时出错
C: 输出0
D: 输出null
正确答案:
(单选题) 3: 给出下列代码,则数组初始化中哪项是不正确的? byte[] array1,array2[]; byte array3[][]; byte [][] array4;
A: array2 = array1
B: array2=array3
C: array2=array4
D: array3=array4
正确答案:
(单选题) 4: 给出下列代码,如何使成员变量m 被方法fun()直接访问? class Test { private int m; public static void fun() { ... } }
A: 将private int m 改为protected int m
B: 将private int m 改为 public int m
C: 将private int m 改为 static int m
D: 将private int m 改为 int m
正确答案:
(单选题) 5: 下列语句序列执行后,k的值是( )。 int j=8, k=15; for( int i=2; i!=j; i++ ) { j-=2; k++; }
A: 15
B: 16
C: 17
D: 18
正确答案:
(单选题) 6: 给出下面的接口: interface A{ int method1(int i); int method2(int j); } 下面那个类实现了这个接口,并且不是抽象的?
A: class B implements A{ int method1(){} int method2(){} }
B: class B { int method1(int i){} int method2(int j){} }
C: class B implements A{ int method1(int i){} int method2(int j){} }
D: class B extends A{ int method1(int i){} int method2(int j){} }
正确答案:
(单选题) 7: 下列程序的功能是在监控台上每隔一秒钟显示一个字符串“Hello”,能够填写在程序中下划线位置,使程序完整并能正确运行的语句是 public class Test implements Runnable{ public static void main(String args[]){ Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run(){ for(;;){ try{
A: sleep(1000) InterruptedException
B: sleep(1000) RuntimeException
C: Thread.sleep(1000) RuntimeException
D: Thread.sleep(1000) InterruptedException
正确答案:
(单选题) 8: Person, Student 和Teacher 都是类名。这些类有以下继承关系。 Person | -------------
------- | | Student Teacher 并且在Java源代码中有如下表达式: Person p = new Student(); 如下哪个语句是正确的?
A: 这条语句是合法的
B: 这条语句是不合法的
C: 编译时出错
D: 编译正确但运行时出错
正确答案:
(单选题) 9: 下面程序的输出结果是什么? String s= "ABCD"; s.concat("E"); s.replace('C','F'); System.out.println(s);
A: 编译错误,字符串是不可改变的
B: ABFDE
C: ABCDE
D: ABCD
正确答案:
(单选题) 10: 下面程序运行后I的结果是什么? Class sree { fun(){ static int I =0; I++; } public static void main(String args[]) { sree obj=new sree(); obj.fun(); obj.fun(); }
A: 编译错误
B: 运行时错误
C: 1
D: 2
正确答案:
(单选题) 11: 在oneMethod()方法运行正常的情况下,程序段将输出什么? public void test(){ try { oneMethod(); System.out.println("condition 1"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("condition 2"); } catch(Exception e) { System.out.println("condition 3");
A: condition 1
B: condition 2
C: condition 3
D: condition 1 finally
正确答案:
(单选题) 12: 给定下面的类:public class Example{ St ring str=new String(“good”); char ch[]={'a','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str+”and”+ex.ch); } public void
A: good and abc
B: good and gbc
C: test ok and abc
D: test ok and gbc
正确答案:
(单选题) 13: 下面语句返回的数据类型是什么? (short)10/10.2*2;
A: int
B: double
C: float
D: short
正确答案:
(单选题) 14: 已知如下的命令执行 java MyTest a b c 请问哪个语句是正确的?
A: args[0] = "MyTest a b c"
B: args[0] = "MyTest"
C: args[0] = "a"
D: args[1]= 'b'
正确答案:
(单选题) 15: 给出如下代码: class Test{ private int m; public static void fun() { // some code... } } 如何使成员变量m被函数fun()直接访问?
A: 将private int m 改为protected int m
B: 将private int m 改为 public int m
C: 将private int m 改为 static int m
D: 将private int m 改为 int m
正确答案:
(单选题) 16: 在程序的源文件开始处有下面一行程序: package awt;
A: 结果是一个编译错误,因为Java已经定义了一个awt包
B: 说明这个文件里的所有的类都应该包含在java.awt包里
C: 说明这个文件里的所有的类都应该包含在自己定义的awt包里
D: 导入你自己定义的awt包里的所有类
正确答案:
(单选题) 17: 下面的语句的作用是:()。 Vector MyVector = new Vector(100,50);
A: 创建一个数组类对象MyVector,有100个元素的空间,每个元素的初值为50。
B: 创建一个向量类对象MyVector,有100个元素的空间,每个元素的初值为50。
C: 创建一个数组类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。D: 创建一个向量类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
正确答案:
(单选题) 18: 下面程序的输出结果是什么?class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }
A: lava
B: java
C: 编译错误
D: 运行时出现异常
正确答案:
(单选题) 19: 下列哪个选项的java源文件代码片段是不正确的?
A: package testpackage; public class Test{ }
B: import java.io.*; package testpackage; public class Test{ }
C: import java.io.*; class Person{ } public class Test{ }
D: import java.io.*; import java.awt.*; public class Test{ }
正确答案:
(单选题) 20: 阅读下列代码后 public class Person{ int arr[]=new int[10]; public static void main(String args[]){ System.out.println(arr[1]); } } 正确的说法是
A: 编译时将产生错误
B: 编译时正确,运行时将产生错误
C: 输出零
D: 输出空
正确答案:
(多选题) 1: 选择所有有效的构造函数。 class Happy { } }
A: public void Happy(){}
B: public Happy(int c){}
C: protected Happy(){}
D: public int Happy(){}
E: void Happy(){}
正确答案:
(多选题) 2: 已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?
A: t.f
B: this.n
C: Test.m
D: Test.n
正确答案:
(多选题) 3: 下面代码执行后的输出是什么?outer: for(int i=0;i<3; i++) inner: for(int j=0;j<2;j++) { if(j==1) continue outer; System.out.println(j+ “ and “+i); }
A: 0 and 0
B: 0 and 1
C: 0 and 2
D: 1 and 0
E: 1 and 1
F: 1 and 2
G: 2 and 0
H: 2 and 1
I: 2 and 2
正确答案:
(多选题) 4: 下面的哪些程序片断可能导致错误。
A: String s="Gonewiththewind"; String t="good"; String k=s+t;
B: String s="Gonewiththewind"; String t; t=s[3]+"one";
C: String s="Gonewiththewind"; String standard=s.toUpperCase();
D: String s="homedirectory"; String t=s-"directory".
正确答案:
(多选题) 5: 请选出创建数组的正确语句。
A: float f[][] = new float[6][6];
B: float []f[] = new float[6][6];
C: float f[][] = new float[][6];
D: float [][]f = new float[6][6];
正确答案:
(多选题) 6: 已知如下代码: public class Test { public static void main(String arg[]) { int i = 5; do { System.out.println(i); } while (--i>5) System.out.println("finished"); } } 执行后的输出结果包括什么?
A: 5
B: 4
C: 6
D: finished
E: 什么都不输出
正确答案:
(多选题) 7: 已知如下定义: String s = "story"; 下面哪些表达式是合法的?
A: s += "books";
B: char c = s[1];
C: int len = s.length;
D: String t = s.toLowerCase();
正确答案:
(多选题) 8: 假定文件名是“Fred.java”,下面哪个是正确的类声明。
A: public class Fred{ public int x = 0; public Fred (int x){ this.x=x; } } B: public class fred{ public int x = 0; public Fred (int x){ this.x=x; } } C: public class Fred extends MyBaseClass{ public int x = 0; }
正确答案:
(多选题) 9: 如果有以下代码,哪几个数字能产生输出"Test2" 的结果? Switch(x){ case 1: System.out.println("Test1"); case 2: case 3: System.out.println("Test2"); break;} System.out.println("Test3"); }
A: 0
B: 1
C: 2
D: 3
正确答案:
(多选题) 10: 针对下面的程序,那些表达式的值是true?Class Aclass{ private long val;
public Aclass(long v){val=v;} public static void main(String args[]){ Aclass x=new Aclass(10L); Aclass y=new Aclass(10L); Aclass z=y; long a=10L; int b=10; } }
A: a==b;
B: a==x;
C: y==z;
D: x==y;
E: a==10.0;
正确答案:
(单选题) 1: 已知如下代码: boolean m = true; if ( m = false ) System.out.println("False"); else System.out.println("True"); 执行结果是什么?
A: False
B: True
C: 编译时出错
D: 运行时出错
正确答案:
(单选题) 2: 有下面的类:public class Example{ static int x[]=new int[15]; public static void main(String args[]){ System.out.println(x[5]); } } 下面的那些说法是正确的。
A: 编译时出错
B: 运行时出错
C: 输出0
D: 输出null
正确答案:
(单选题) 3: 给出下列代码,则数组初始化中哪项是不正确的? byte[] array1,array2[]; byte array3[][]; byte [][] array4;
A: array2 = array1
B: array2=array3
C: array2=array4
D: array3=array4
正确答案:
(单选题) 4: 给出下列代码,如何使成员变量m 被方法fun()直接访问? class Test { private int m; public static void fun() { ... } }
A: 将private int m 改为protected int m
B: 将private int m 改为 public int m
C: 将private int m 改为 static int m
D: 将private int m 改为 int m
正确答案:
(单选题) 5: 下列语句序列执行后,k的值是( )。 int j=8, k=15; for( int i=2; i!=j; i++ ) { j-=2; k++; }
A: 15
B: 16
C: 17
D: 18
正确答案:
(单选题) 6: 给出下面的接口: interface A{ int method1(int i); int method2(int j); } 下面那个类实现了这个接口,并且不是抽象的?
A: class B implements A{ int method1(){} int method2(){} }
B: class B { int method1(int i){} int method2(int j){} }
C: class B implements A{ int method1(int i){} int method2(int j){} }
D: class B extends A{ int method1(int i){} int method2(int j){} }
正确答案:
(单选题) 7: 下列程序的功能是在监控台上每隔一秒钟显示一个字符串“Hello”,能够填写在程序中下划线
位置,使程序完整并能正确运行的语句是 public class Test implements Runnable{ public static void main(String args[]){ Test t=new Test(); Thread tt=new Thread(t); tt.start(); } public void run(){ for(;;){ try{
A: sleep(1000) InterruptedException
B: sleep(1000) RuntimeException
C: Thread.sleep(1000) RuntimeException
D: Thread.sleep(1000) InterruptedException
正确答案:
(单选题) 8: Person, Student 和Teacher 都是类名。这些类有以下继承关系。 Person | -------------------- | | Student Teacher 并且在Java源代码中有如下表达式: Person p = new Student(); 如下哪个语句是正确的?
A: 这条语句是合法的
B: 这条语句是不合法的
C: 编译时出错
D: 编译正确但运行时出错
正确答案:
(单选题) 9: 下面程序的输出结果是什么? String s= "ABCD"; s.concat("E"); s.replace('C','F'); System.out.println(s);
A: 编译错误,字符串是不可改变的
B: ABFDE
C: ABCDE
D: ABCD
正确答案:
(单选题) 10: 下面程序运行后I的结果是什么? Class sree { fun(){ static int I =0; I++; } public static void main(String args[]) { sree obj=new sree(); obj.fun(); obj.fun(); }
A: 编译错误
B: 运行时错误
C: 1
D: 2
正确答案:
(单选题) 11: 在oneMethod()方法运行正常的情况下,程序段将输出什么? public void test(){ try { oneMethod(); System.out.println("condition 1"); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("condition 2"); } catch(Exception e) { System.out.println("condition 3");
A: condition 1
B: condition 2
C: condition 3
D: condition 1 finally
正确答案:
(单选题) 12: 给定下面的类:public class Example{ String str=new String(“good”); char ch[]={'a','b','c'}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.println(ex.str+”and”+ex.ch); } public void
A: good and abc
B: good and gbc
C: test ok and abc
D: test ok and gbc
正确答案:
(单选题) 13: 下面语句返回的数据类型是什么? (short)10/10.2*2;
A: int
B: double
C: float
D: short
正确答案:
(单选题) 14: 已知如下的命令执行 java MyTest a b c 请问哪个语句是正确的?
A: args[0] = "MyTest a b c"
B: args[0] = "MyTest"
C: args[0] = "a"
D: args[1]= 'b'
正确答案:
(单选题) 15: 给出如下代码: class Test{ private int m; public static void fun() { // some code... } } 如何使成员变量m被函数fun()直接访问?
A: 将private int m 改为protected int m
B: 将private int m 改为 public int m
C: 将private int m 改为 static int m
D: 将private int m 改为 int m
正确答案:
(单选题) 16: 在程序的源文件开始处有下面一行程序: package awt;
A: 结果是一个编译错误,因为Java已经定义了一个awt包
B: 说明这个文件里的所有的类都应该包含在java.awt包里
C: 说明这个文件里的所有的类都应该包含在自己定义的awt包里
D: 导入你自己定义的awt包里的所有类
正确答案:
(单选题) 17: 下面的语句的作用是:()。 Vector MyVector = new Vector(100,50);
A: 创建一个数组类对象MyVector,有100个元素的空间,每个元素的初值为50。
B: 创建一个向量类对象MyVector,有100个元素的空间,每个元素的初值为50。
C: 创建一个数组类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。D: 创建一个向量类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
正确答案:
(单选题) 18: 下面程序的输出结果是什么?class Foo{ static void change(String s){ s=s.replace('j','l'); } public static void main(String args[]){ String s="java"; change(s); System.out.println(s); } }
A: lava
B: java
C: 编译错误
D: 运行时出现异常
正确答案:
(单选题) 19: 下列哪个选项的java源文件代码片段是不正确的?
A: package testpackage; public class Test{ }
B: import java.io.*; package testpackage; public class Test{ }
C: import java.io.*; class Person{ } public class Test{ }
D: import java.io.*; import java.awt.*; public class Test{ }
正确答案:
(单选题) 20: 阅读下列代码后 public class Person{ int arr[]=new int[10]; public static void main(String args[]){ System.out.println(arr[1]); } } 正确的说法是
A: 编译时将产生错误
B: 编译时正确,运行时将产生错误
C: 输出零
D: 输出空
正确答案:
(多选题) 1: 选择所有有效的构造函数。 class Happy { } }
A: public void Happy(){}
B: public Happy(int c){}
C: protected Happy(){}
D: public int Happy(){}
E: void Happy(){}
正确答案:
(多选题) 2: 已知如下类说明: public class Test { private float f = 1.0f; int m = 12; static int n=1; public static void main(String arg[]) { Test t = new Test(); // 程序代码… } } 如下哪个使用是正确的?
A: t.f
B: this.n
C: Test.m
D: Test.n
正确答案:
(多选题) 3: 下面代码执行后的输出是什么?outer: for(int i=0;i<3; i++) inner: for(int j=0;j<2;j++) { if(j==1) continue outer; System.out.println(j+ “ and “+i); }
A: 0 and 0
B: 0 and 1
C: 0 and 2
D: 1 and 0
E: 1 and 1
F: 1 and 2
G: 2 and 0
H: 2 and 1
I: 2 and 2
正确答案:
(多选题) 4: 下面的哪些程序片断可能导致错误。
A: String s="Gonewiththewind"; String t="good"; String k=s+t;
B: String s="Gonewiththewind"; String t; t=s[3]+"one";
C: String s="Gonewiththewind"; String standard=s.toUpperCase();
D: String s="homedirectory"; String t=s-"directory".
正确答案:
(多选题) 5: 请选出创建数组的正确语句。
A: float f[][] = new float[6][6];