信管071班复习资料~~Java程序设计
一、单项选择题
1.指出正确的表达式()。 A. byte = 128; B. Boolean = null; C. long l = 0xfffL; D. double = 0.9239d; 2.指出下列程序运行的结果 public class Example{
String str=new String(\ char[]ch={'a','b','c'};
public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch);
System.out.print(ex.str+\ System.out.print(ex.ch); }
public void change(String str,char ch[]){ str=\ ch[0]='g'; } }
A.good and abc B.good and gbc C.test ok and abc D.test ok and gbc 3.给出下面代码: public class Person{
static int arr[] = new int[10];
public static void main(String a[]) {
System.out.println(arr[1]); } }
那个语句是正确的?
A. 编译时将产生错误; B. 编译时正确,运行时将产生错误;
C .输出零; D. 输出空。
4.哪个关键字可以对对象加互斥锁?
A. transient B. synchronized C.serialize D.static5.下列代码哪几行会出错: 1) public void modify() { 2) int I, j, k; 3) I = 100;
1
4) while ( I > 0 ) { 5) j = I * 2;
6) System.out.println (\7) k = k + 1; 8) I--; 9) } 10}
A. line 4 B. line 6 C. line 7 D. line 8
6.MAX_LENGTH是int型public成员变量, 变量值保持为常量100,用简短语句定义这个变量。
A. public int MAX_LENGTH=100; B. final int MAX_LENGTH=100;
C. final public int MAX_LENGTH=100; D. public final int MAX_LENGTH=100; 7.给出下面代码:
1) class Parent {
2) private String name; 3) public Parent(){} 4) }
5) class Child extends Parent { 6) private String department; 7) public Child() {}
8) public String getValue(){ return name; } 9) public static void main(String arg[]) { 10) Parent p = new Parent(); 11) } 12)}
那些行将引起错误?
A. 第3行 B. 第6行 C. 第7行 D. 第8行
8.给出下面代码段
1) public class Test { 2) int m, n;
3) public Test() {}
4) public Test(int a) { m=a; }
5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k;
8) j = 0; k = 0; 9) t1 = new Test(); 10) t2 = new Test(j,k); 11) } 12)}
哪行将引起一个编译时错误?
2
A.line 3 B.line 5 C.line 6 D. line 10
9.对于下列代码: 1) class Person {
2) public void printValue(int i, int j) {//... } 3) public void printValue(int i){//... } 4) }
5) public class Teacher extends Person { 6) public void printValue() {//... } 7) public void printValue(int i) {//...} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) }
第10行语句将调用哪行语句??
A. line 2 B. line 3 C. line 6 D. line 710.哪个关键字可以抛出异常?
A. transient B. finally C. throw D. static 11.Main()方法的返回类型是:
A. int B. void C. Boolean D. static 12.System类在哪个包中?
A. java.util B. java.io C. java.awt D. java.lang 13.给出下面代码: public class test{
static int a[] = new a[10];
public static void main(String args[]) { System.out.println(arr[10]); } }
那个选项是正确的?
A. 编译时将产生错误 B. 编译时正确,运行时将产生错误 C. 输出零 D. 输出空
14.下面哪个选项是正确的main方法说明? A. public main(String args[])
B. public static void Main(String args[]) C. private static void main(String args[]) D. public static void main(String[] args) 15.给定下面的代码片段: 1) String str = null;
2) if ((str != null) && (str.length() > 10)) { 3) System.out.println(\ 4) }
5) else if ((str != null) & (str.length() < 5)) { 6) System.out.println(\ 7) }
3
8) else { System.out.println(\哪些行会导致错误?
A. line 1 B. line 2 C. line 5 D. line 8 16.下面哪种注释方法能够支持javadoc命令:
A. /**...**/ B. /*...*/ C. // D. /**...*/
17.看下面一段程序: class Aclass{ void go(){
System.out.println(\ } }
public class Bclass extends Aclass{ void go(){
System.out.println(\ }
public static void main(String args[]){ Aclass a=new Aclass(); Aclass a1=new Bclass(); a.go(); a1.go(); }
以上程序运行结果是:
A. Aclass B. Bclass Aclass Bclass C. Aclass D. Bclass Bclass Aclass 18.指出下列程序的运行结果 int i = 9; switch (i) { default:
System.out.println(\ case 0:
System.out.println(\ break; case 1:
System.out.println(\ case 2:
System.out.println(\ }
A. default B. default
zero
C. error default clause not defined D.
不会有任何输出
4
19.下面哪个单词是Java语言的关键字( )
A.Float B.this C.string D.unsigned 20.下面哪个是Java语言中正确的标识符( ) A.3com B.import C.that D.this
21.下面哪个修饰符修饰的方法只能被本类中的其他方法使用( ) A.protected B.static C.private D.public 22.下面哪个是对字符串String的正确定义 ( )
A.String s1 = null; B.String s2 = ’null’ ;
C.String s3 = (String)’abc’ ; D.String s4 = new String(‘uface’); 23.下面哪条语句定义了5个元素的数组( ) A.int[] a = {22,23,24,25,12}; B.int a[] = new int(5); C.int[5] array; D.int[] arr;
24.给出一段程序,选择运行结果( ) public class sss {
public static void main(String args[]) {
String s1=args[1]; String s2=args[2]; String s3=args[3]; String s4=args[4]; System.out.println(“args[2]=“+s2); } }
命令行执行: java sss 1 2 3 4 结果是下面哪一个?
A.args[2]=2 B.args[2]=null C.args[2]=1 D.运行出现异常 25.下面程序段的输出结果是( )。 String MyStr = \ MyStr = MyStr + \ System.out.println(MyStr); A. Hello,Guys! B. Hello,
C. Guys! D. 该程序段有语法错误 26.给出下面一段程序,选择运行结果( ) public class X{
public static void main(String [] args){ String names[]=new String[5];
for(int x=0;x
命令行执行: java X a b 结果是下面哪一个?
A.names B.b C.null D. 运行出现异常 27.下面哪个是Java语言中正确的标识符( )
A.3D B.$this C.extends D.implements
28.下面哪项可以得到数组元素的个数,java中定义数组名为 abc,( ) A.abc.length( ) B.abc.length C.len(abc) D.ubound(abc)
5