第二章练习题(数据类型和运算符)
1.下列哪项不属于Java语言的基本数据类型? A.int B.String C.double D.boolean
2.下列哪项不是int类型的字面量? A.\Φ B.077
C.OxABBC D.20
3.下列哪项不是有效的标识符? A.userName B.2test C.$change D._password
4.下列哪项是Java语言中所规定的注释样式?(选三项) A.//单行注释 B.--单行注释 C. /*
*单行或多行注释 */ D. /kk *文档注释 */
5.下列哪项不是Java语言的关键字? A.goto B.sizeof C.instanceof D.volatile
1-6
6.现有如下五个声明:
Linel: int a_really_really_really_long_variable_name=5 ; Line2: int _hi=6;
Line3: int big=Integer. getlnteger(\ Line4:int $dollars=8; line5: int %opercent=9; 哪行无法通过编译? A.Line1 B.Line3 C. Line4 D. Line5
7.现有:
1. class Top {
2. static int x=l;
3. public Top (inty) { x*=3; } 4. }
5. class Middle extends Top { 6. public Middle() {x+=1; )
7. public static void main (String [] args) 8. Middle m = new Middle(); 9. System. out .println (x); IO. } II. } 结果为: A.1 B. 2 C.3
D.编译失败
8.现有:
1. class Passer f
2. static final int X=5;
3.public static void main (String [] args) { 4. new Passer().go (x); 5.System. out .print (x); 6, )
7. void go (int x) { 8.System. out .print(x++); 9. } 10. }
{ 1-7
结果是什么? A.55 B.56 C.65 D.66
9.现有:
1. class Wrench f
2.public static void main(String [] args) {
3.Wrench w=new Wrench(); Wrench w2=new Wrench(); 4. w2=go (w, w2); 5.System.out.print (w2==w); 6. }
7.static Wrench go (Wrench wrl, Wrench wr2) { 8.Wrench wr3=wrl; wrl=wr2; wr2=wr3; 9. return wr3; 10. } 11. }
结果是什么? A. false B. true C.编译失败
D.运行的时候有异常抛出
10.现有:
5. class Wrench2 { 6. int size;
7.public static void main(String [] args) { 8.Wrench2 w=new Wrench2(); 9. w.size=II;
IO. Wrench2 w2=go(w, w.size); II. System. out .print (w2. size); 12. )
13. static Wrench2 go(Wrench2 wr. int s) { 14. S=12;
15。 return wr; 16. } 17. }
1-8
结果为: A. 11 B. 12
c.编译失败。
D.运行时异常被抛出
11.现有: class Test2 f
public static void main (String [] args) { short a,b,C; a=l; b=2;
C=a+b; a+=2: } }
以上代码中,哪一句是错误的? A.a=1: B.C=a+b; C. a+=2;
D. short a,b,C;
12.表达式:1-2/5+2 'k5的结果是哪项? A. 10.6 B. 9.8 C. 9
13.现有代码片段: String s=\; String sl=S+456;
请问sl的结果是哪项? A. 123456 B. 579
C.编译错误
D.运行时抛出异常
1-9
14.基本数据类型float的包裹类是哪项? A. Integer B. Double C. Float
D. Character
15.现有:
1. class Test4 {
2. public static void main (String [] args) { 3. boolean X=true; 4. boolean y=false; 5. short Z=42; 6.
7. if((z++==42) && (y=true))z++; 8.if((x=false) || (++z==45)) z++; 9.
10. System. out.println(¨z=”+z); II. } 12. } 结果为: A. Z=42 B. z=44 C. Z= 45 D. z= 46
1-10