第一章 单元测试

1、单选题:编译和运行以下代码的结果为:  public class MyMain{         public static void main(String argv){          System.out.println(“Hello cruel world”);       } }

A:编译错误
B:运行输出 ‘Hello cruel world’
C:编译无错,但运行时指示没有定义构造方法
D:编译无错,但运行时指示找不到main方法
正确答案:【编译无错,但运行时指示找不到main方法】

2、单选题:以下哪个是Java应用程序入口的main方法头?
A:public static void main(String a[])
B:public static int main(char args[])
C:public static void main(String argv)
D:public static void MAIN(String args[])
正确答案:【public static void main(String a[]) 】

3、单选题:编译Java源程序文件将产生相应的字节码文件,字节码文件的扩展名为?
A:exe
B:java
C:class
D:html
正确答案:【class】

4、多选题:

main方法是Java  Application程序执行的入口点,关于main方法的方法头合法的有?

A:public static void main()
B:public static void main(String[ ] args)
C:public static void main(String arg[ ])
D:public static int main(String[ ] arg)
正确答案:【public static void main(String[ ] args);public static void main(String arg[ ])】

5、判断题:

每个源程序文件中只能定义一个类。

A:对
B:错
正确答案:【错】

第二章 单元测试

1、单选题:在Java中,十进制数16的十六进制表示格式是?
A:0xA
B:0x10
C:016
D:0x16
正确答案:【0x10】

2、单选题:要产生[10,100]之间的随机整数使用哪个表达式?
A:(int)(Math.random()*100)
B:10+(int)Math.random()*90
C:10+(int)Math.random()*91
D:10+(int)(Math.random()*91)
正确答案:【10+(int)(Math.random()*91)】

3、单选题:下列符号中不能作为Java标识符的是?
A:abc
B:$str1
C: _pore
D:45six
正确答案:【45six】

4、单选题:下面各项中定义变量及赋值不正确的是?
A:double d = 45.0;
B:char c = 65;
C:float f = 45.0;
D:int i = 32;
正确答案:【float f = 45.0;】

5、单选题:

执行以下代码段后, x, a,和 b的值为?  
int x, a = 6, b = 7;  
x = a++ + b++;

A:x= 13, a=6, b=7
B:x= 15, a=6, b=7
C:x= 15, a=7, b=8
D:x= 13, a=7, b=8
正确答案:【x= 13, a=7, b=8】

6、单选题:下列哪个不是Java的保留字?
A:extends
B:cin
C:class
D:float
正确答案:【cin】

7、多选题:

哪些赋值是合法的?

A: float f = -412;
B:long test = 012;
C:int other = (int)true;
D:double d = 0x12345678;
正确答案:【 float f = -412;;long test = 012; ;double d = 0x12345678; 】

8、多选题:下列代码中,将引入编译错误的行是1 public class Exercise{2  public static void main(String args[]){3     float f = 0.0 ;4     f = f + 1.0 ;5  }6 }
A:第3行
B:第6行
C:第4行
D:第2行
正确答案:【第3行;第4行】

9、多选题:下列哪些是合法标识符?
A:$persons
B:*point
C:this
D:TwoUsers
正确答案:【$persons ;TwoUsers】

10、多选题:下列哪些是java中有效的整数表示形式?
A:22H
B:0x22
C:022
D:22
正确答案:【0x22;022;22】

第三章 单元测试

1、单选题:如何更改break语句使退出inner和middle循环,继续外循环的下一轮? outer: for (int x = 0; x < 3; x++) { middle: for (int y = 0; y < 3; y++) { inner: for (int z = 0; z < 3; z++) {         if (arr(x, y, z) == targetValue)            break;       }   }}

A: continue;
B:break outer;
C:break middle;
D:break inner;
正确答案:【break middle; 】

2、单选题:以下程序的输出结果为?public class Test {   public static void main(String args[]) {     for ( int k = 0; k < 3; k++)          System.out.print(“k”);   } }
A:kkk
B:k
C:012
D:0123
正确答案:【kkk】

3、单选题:以下代码的调试结果为?1:    public class Q102:    {3:      public static void main(String[] args)4:      {5:          int i = 10;6:          int j = 10;7:          boolean b = false;8:          9:          if( b = i == j)10:            System.out.println(“True”);11:         else12:            System.out.println(“False”);13:       }14:    }

A:在第9行出现运行异常
B:输出 :True
C:在第9行出现编译错误
D:输出 :False
正确答案:【输出 :True】

4、单选题:以下代码的调试结果为?public class test {  public static void main(String args[]) {     int i = 1;    do {        i–;    } while (i > 2);    System.out.println(i);  }}
A:1
B:2
C:0
D:-1
正确答案:【0】

5、单选题:下面的代码段执行之后count的值是什么?    int count = 0;    for (int i = 1; i < 4; i++) {         count += i;    }    System.out.println(count);
A:1
B:6
C:4
D:10
正确答案:【6】

6、单选题:以下程序的运行结果为:     1. public class Conditional {     2.    public static void main(String args [] )  {     3.      int x = 4;     4.      System.out.println( “value is ” +     5.         ((x > 4)  ? 99.99 : 9));     6.    }     7.  }

A:输出: value is 9.0
B:输出: value is 9
C:在第5行出现编译错误
D:输出:value is 99.99
正确答案:【输出: value is 9.0】

7、单选题:下列程序的运行结果?public class Test {    public static void main(String a[]) {        int x=3,y=4,z=5;        if (x>3) {          if (y<2)            System.out.println(“show one”);          else            System.out.println(“show two”);         }         else {           if (z>4)            System.out.println(“show three”);          else            System.out.println(“show four”);         }    }}
A: show three
B:show four
C:show one
D:show two
正确答案:【 show three 】

8、单选题:以下程序调试结果 public class test {   public static void main(String args[]) {       int i=1, j=3;      while (j>0) {         j–;         i++;               }       System.out.println(i);   }}
A:0
B:2
C:3
D:4
正确答案:【4】

9、多选题:在switch(expression)语句中,expression的数据类型不能是?
A:boolean
B:double
C:char
D:byte
正确答案:【boolean;double】

10、多选题:假设a是int类型变量,并初始化为1,则下列哪个为合法的条件语句?
A:if (a=2) { }
B:if (a) { }
C: if (true) { }
D: if (a<3) { }
正确答案:【 if (true) { }; if (a<3) { } 】

第四章 单元测试

1、单选题:

以下程序运行时输入:

java Cycle hello two me 2

public class Cycle{

public static void main(String args[]){

System.out.println(args[1]);

}

}

则运行结果为?
A:hello
B:2
C:me
D:two
正确答案:【two】

2、单选题:

public class test {
  public static void main(String args[]) {
    int m=0;
    for ( int k=0;k<2;k++)
      method(m++);
    System.out.println(m);
  }
  public static void method(int m) {
    System.out.print(m);
  }

A:123
B:012
C:111
D:000
正确答案:【012】

3、单选题:

以下程序运行结果为:
public class Q {
   public static void main(String argv[]) {
      int anar[]= new int[5];
      System.out.println(anar[0]);
   }
}

A:”null”
B:0
C:出错: anar在未初始化前被引用
D:5
正确答案:【0】

4、单选题:

下列程序的运行结果是:

public class Test {

public static void main(String args[]) {

int m[]={1,2,3,4,5,6,7,8};

int sum = 0;

for (int i=0;i<8;i++){

sum = sum + m[i];

if (i==3) break;

}

System.out.println(sum);

}

}
A:36
B:6
C:3
D:10
正确答案:【10】

5、单选题:

下面定义和给数组初始化正确的是:

A:String temp = {”a”, ”b”, ”c”};
B:String temp [] = { ‘j ‘, ‘ b’ ,’c’};
C:String temp [] = new String {”j” ”a” ”z”};
D:String temp [] = {”a”, ”b”, ”c”};
正确答案:【String temp [] = {”a”, ”b”, ”c”};】

6、单选题:在注释//Start For loop 处要插入哪段代码可以实现根据变量i的值定位访问数组ia[]的所有元素。 public class Lin{    public void amethod(){        int ia[] = new int[4];         //Start For loop               {        ia[i]=i;                  System.out.println(ia[i]);           }       }  }
A:for (int i=0; i< ia.length;i++)
B:for (int i=0; i< ia.length(); i++)
C:for (int i=0; i< ia.length-1; i++)
D:for (int i=0; i < ia.length() -1; i++)
正确答案:【for (int i=0; i< ia.length;i++)】

7、单选题:设有如下程序,其调试结果为:class Q2 {       public static void main(String[] args) {         int[] seeds = {1,2,3,4,6,8};         int n= seeds.length;        for (int i = 0; i < 3; i++)           for (int k = 0; k< n-1; k++)            seeds[k]= seeds[k+1];         for (int i = 0; i <n; i++)            System.out.print(“t”+seeds[i]);        }}
A:输出: 4 6 8 8 8 8
B:输出: 1 2 3 4 6 8
C:输出: 2 3 4 6 8 8
D:输出: 2 3 4 6 6 8
正确答案:【输出: 4 6 8 8 8 8】

8、多选题:下列选项能正确定义一个整形数组的是: A:int scores[];
B:int scores={0,0,0,0};
C:int[] scores;
D:int scores=new int[10];
正确答案:【int scores[];;int[] scores;】

9、多选题:

设有如下代码: int[] x = new int[25]; 执行后,以下哪个说法正确?

A:x[25] 为 0.
B:x[24] 为 0
C:x.length 为 25.
D:x[0] 为null.
正确答案:【x[24] 为 0;x.length 为 25.】

第五章 单元测试

1、单选题:关于以下程序的说明,正确的是(        )
1.  class   StaticStuff2. { 3.     static  int  x=10;4.     static  { x+=5;}5.     public  static  void  main(String  args[ ])6.     {7.        System.out.println(“x=” + x);8.      }9.     static  { x/=3;}10.   }

A:编译通过,执行结果为:x=5
B:编译通过,执行结果为:x=3
C:9行不能通过编译,因为只能有一个静态初始化器
D:4行与9行不能通过编译,因为缺少方法名和返回类型
正确答案:【编译通过,执行结果为:x=5】

2、单选题:

以下程序编译和运行会发生什么

public class Q8   {

int i = 20;

static { int i = 10;  }

public static void main(String[] args)  {

Q8 a = new Q8();

System.out.println(a.i);

}

}
A:编译错误,静态初始化只能用于初始化目的
B:编译错误,变量 ‘i’ 定义2次.
C:输出 20.
D:输出 10.
正确答案:【输出 20.】

3、单选题:

给出如下类定义: 
public class test {    
  test(int k) { } 
}
如果要创建一个该类的对象,正确的语句是:

A:test obj1 = new test(‘5 ‘);
B:test obj1 = new test(5);
C:test obj1 = new test(3.4);
D:test obj1 = new test();
正确答案:【test obj1 = new test(5);】

4、单选题:有如下代码:public class Person { …  }下列哪个符合该类的构造方法定义

A:public static void Person() {…}
B:public Person() {…}
C:public int Person() {…}
D:public void Person() {…}
正确答案:【public Person() {…}】

5、单选题:以下代码的输出结果?
public class Test{
static int x=5;
public static void main(String argv[]){
change(x);
x++;
System.out.println(x);
}
static void change(int m){
m+=2;
}}
A:8
B:7
C:5
D:6
正确答案:【6】

6、单选题:设有如下程序:public class Test5 {    public static void main (String args []) {     /* This is the start of a comment            if (true) {                  Test5 = new test5();             System.out.println(“Done the test”);       }         /* This is another comment */          System.out.println (“The end”);   }}结果为?
A:程序输出”Done the test”和 “The end”
B:程序编译错误.
C: 程序输出”The end”
D:输出 “Done the test”.
正确答案:【 程序输出”The end”】

7、多选题:给出下面的不完整的类代码:class Person {
String name, department;
int age;
public Person(String n){ name = n; }
public Person(String n, int a){ name = n; age = a; }
public Person(String n, String d, int a) {
// doing the same as two arguments version of constructor
// including assignment name=n,age=a
department = d;
}
}
下面的哪些表达式可以加到构造方法中的”doing the same as…”处?
A:name=n;age=a;
B:Person(n,a);
C:this(n,a);
D:this(name,age);
正确答案:【name=n;age=a;;this(n,a);】

8、多选题:

考虑如下类:

public class Test {         int j,k;             public Test(int j ) {             this(j,0);       }       public Test(int j, int k)  {         this.j=j;              this.k=k;       }  }

以下哪些可正确创建Test对象?

A:Test t = new Test(1, 2, 3);
B:Test t = new Test(1, 2);
C:Test t = new Test();
D:Test t = new Test(1);
正确答案:【Test t = new Test(1, 2);;Test t = new Test(1);】

第六章 单元测试

1、单选题:在Java中,如下的修饰符不是访问控制修饰符
A:private
B:static
C:public
D:protected
正确答案:【static】

2、单选题:类Test1定义如下:1.public  class  Test1{2.     public  float  aMethod(float  a,float  b){   }3.        4.}
将以下哪种方法插入行3是不合法的。

A:public float aMethod(float a, float b,float c){ }
B:private float aMethod(int a,int b,int c){ }
C:public int aMethod(int a, int b){ }
D:public float aMethod(float c,float d){ }
正确答案:【public float aMethod(float c,float d){ }】

剩余章节答案支付后查看
如有疑问请及时联系QQ 50895809反馈
如遇卡顿看不了剩余内容请换个浏览器即可打开

没找到的科目也可以提醒我们更新

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注