第一章 单元测试

 

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

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

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

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

4、多选题:

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

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

5、判断题:

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

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

第二章 单元测试

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

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

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

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

5、单选题:

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

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

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

7、多选题:

哪些赋值是合法的?

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

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:第6行
B:第4行
C:第3行
D:第2行
正确答案:【第4行;
第3行】

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

10、多选题:下列哪些是java中有效的整数表示形式?
A:22H
B:022
C:0x22
D:22
正确答案:【022;
0x22;
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 middle;
C:break outer;
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:0123
B:kkk
C:012
D:k
正确答案:【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:在第9行出现运行异常
C:输出 :False
D:输出 :True
正确答案:【输出 :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:1
D:0
正确答案:【0】

5、单选题:下面的代码段执行之后count的值是什么?    int count = 0;    for (int i = 1; i < 4; i++) {         count += i;    }    System.out.println(count);
A:6
B:1
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
B:在第5行出现编译错误
C:输出: value is 9.0
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 one
C:show four
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:2
B:4
C:0
D:3
正确答案:【4】

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

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

第四章 单元测试

1、单选题:

以下程序运行时输入:

java Cycle hello two me 2

public class Cycle{

public static void main(String args[]){

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

}

}

则运行结果为?
A:2
B:two
C:me
D:hello
正确答案:【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:000
C:111
D:012
正确答案:【012】

3、单选题:

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

}
A:出错: anar在未初始化前被引用
B:”null”
C:0
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:6
B:36
C:10
D:3
正确答案:【10】

5、单选题:

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

A:String temp [] = {”a”, ”b”, ”c”};
B:String temp = {”a”, ”b”, ”c”};
C:String temp [] = { ‘j ‘, ‘ b’ ,’c’};
D:String temp [] = new String {”j” ”a” ”z”};
正确答案:【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-1; i++)
C:for (int i=0; i< ia.length;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:输出: 1 2 3 4 6 8
B:输出: 4 6 8 8 8 8
C:输出: 2 3 4 6 6 8
D:输出: 2 3 4 6 8 8
正确答案:【输出: 4 6 8 8 8 8】

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

9、多选题:

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

A:x[25] 为 0.
B:x[0] 为null.
C:x[24] 为 0
D:x.length 为 25.
正确答案:【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:4行与9行不能通过编译,因为缺少方法名和返回类型
B:编译通过,执行结果为:x=3
C:编译通过,执行结果为:x=5
D: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:输出 20.
B:编译错误,静态初始化只能用于初始化目的
C:输出 10.
D:编译错误,变量 ‘i’ 定义2次.
正确答案:【输出 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 Person() {…}
B:public static void Person() {…}
C:public void Person() {…}
D:public int 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:6
C:5
D:7
正确答案:【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:程序编译错误.
B:程序输出”Done the test”和 “The end”
C:输出 “Done the test”.
D: 程序输出”The end”
正确答案:【 程序输出”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:Person(n,a);
B:this(name,age);
C:this(n,a);
D:name=n;age=a;
正确答案:【this(n,a);;
name=n;age=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(l);
B:Test t = new Test();
C:Test t = new Test(l, 2);
D:Test t = new Test(l, 2, 3);
正确答案:【Test t = new Test(l);;
Test t = new Test(l, 2);】

第六章 单元测试

1、单选题:在Java中,如下的修饰符不是访问控制修饰符
A:static
B:protected
C:private
D:public
正确答案:【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:public int aMethod(int a, int b){ }
C:public float aMethod(float c,float d){ }
D:private float aMethod(int a,int b,int c){ }
正确答案:【public float aMethod(float c,float d){ }】

3、单选题:以下代码调试结果
class Base {}
class Sub extends Base {}
public class CEx{
public static void main(String argv[]){
Base b = new Base();
Sub s = (Sub) b;
}
}

A:编译异常
B:运行异常
C:运行没输出
D:调试通过
正确答案:【运行异常】

4、单选题:

如何定义一个不能有子类的类Key?

A:abstract final class Key { }
B:class Key { }
C:native class Key { }
D:final class Key { }
正确答案:【final class Key { } 】

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

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

发表回复

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