尾部都有答案
第二章练习题(数据类型和运算符)
(1)下列哪项不属于Java语言的基本数据类型?
A.int
B.String
C.double
D.boolean
(2)下列哪项不是int类型的字面量?
A.\u03A6
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
(6)现有如下五个声明
Linel: int a_really_really_really_long_variable_name=5 ;
Line2: int _hi=6;
Line3: int big=Integer. getlnteger("7”);
Line4:int $dollars=8;
line5: int %opercent=9;
哪行无法通过编译?
A. Line1
B. Line3
C. Line4
D. Line5
(7)现有
class Top {
static int x=l;
public Top (inty) { x*=3; }
}
class Middle extends Top {
public Middle() {x+=1; )
public static void main (String [] args) {
Middle m = new Middle();
System. out .println (x);
}
}
结果为
A. 1
B. 2
C. 3
D. 编译失败
(8)现有
class Passer {
static final int X=5;
public static void main (String [] args) {
new Passer().go (x);
System. out .print (x);
)
void go (int x) {
System. out .print(x++);
}
}
结果是什么?
A.55
B.56
C.65
D.66
(9)现有
class Wrench {
public static void main(String [] args) {
Wrench w=new Wrench(); Wrench w2=new Wrench();
w2=go (w, w2);
System.out.print (w2==w);
}
static Wrench go (Wrench wrl, Wrench wr2) {
Wrench wr3=wrl; wrl=wr2; wr2=wr3;
return wr3;
}
}
结果是什么?
A. false
B. true
C. 编译失败
D. 运行的时候有异常抛出
(10)现有:
class Wrench2 {
int size;
public static void main(String [] args) {
Wrench2 w=new Wrench2();
w.size=II;
Wrench2 w2=go(w, w.size);
System. out .print (w2. size);
)
static Wrench2 go(Wrench2 wr. int s) {
S=12;
return wr;
}
}
结果为:
A. 11
B. 12
C.编译失败。
D.运行时异常被抛出
(11)现有
Class Test2 {
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 = "123";
String sl = S+456;
请问sl的结果是哪项?
A. 123456
B. 579
C.编译错误
D.运行时抛出异常
(14)基本数据类型float的包裹类是哪项?
A. Integer
B. Double
C. Float
D. Character
(15)现有
class Test4 {
public static void main (String [] args) {
Boolean X=true;
Boolean y=false;
short Z=42;
if((z++==42) && (y=true))z++;
if((x=false) || (++z==45)) z++;
System. out.println(¨z=”+z);
}
}
结果为:
A. Z=42
B. z=44
C. Z= 45
D. z= 46
参考答案
1、B
2、A
3、B
4、ACD
5、B
6、D
7、D
8、A
9、B
10、A
11、B
12、D
13、A
14、C
15、D