网站导航:首页 -> JAVA认证 -> JAVA认证考试题库 -> JAVA认证历年真题:SCJP认证套题解析-1-

JAVA认证历年真题:SCJP认证套题解析-1-

1. which of the following range of short is correct?
a. -27 -- 27-1
b. 0 -- 216-1
c. ?215 -- 215-1
d. ?231 -- 231-1
翻译 下面哪些是short型的取值范围。
答案
c 解析
短整型的数据类型的长度是16 bits,有符号。另外需要说明的是java中所有的整(integral)数(包括byte,short,int,long)全是有符号的。
2. which declarations of identifiers are legal?
a. $persons
b. twousers
c. *point
d. this
e. _endline
翻译 下面哪些是合法的标识符。
答案
a,b,e 解析
java的标识符可以以一个unicode字符,下滑线(_),美元符($)开始,后续字符可以是前面的符号和数字,没有长度限制,大小写敏感,不能是保留字。
3. which statement of assigning a long type variable to a hexadecimal value is correct?
a. long number = 345l;
b. long number = 0345;
c. long number = 0345l;
d. long number = 0x345l
翻译 哪些是将一个十六进制值赋值给一个long型变量。
答案
d 解析
十六进制数以0x开头,long型数以l(大小写均可,一般使用大写,因为小写的l和数字1不易区分)。
4.which of the following fragments might cause errors?
a. string s = 'gone with the wind';
string t = ' good ';
string k = s + t;
b. string s = 'gone with the wind';
string t;
t = s[3] + 'one';
c. string s = 'gone with the wind';
string standard = s.touppercase();
d. string s = 'home directory';
string t = s - 'directory';
翻译 下面的哪些程序片断可能导致错误。
答案b,d 解析
a:string类型可以直接使用+进行连接运算。
b:string是一种object,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误。
c:touppercase()方法是string对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(string类型)。
d:string类型不能进行减(-)运算,错误。