16.现有:
3. class Parser extends Utils {
4. public static void main(String [] args) { 5. System.out.print(new Parser().getInt(\)); 6. }
7. int getInt(String arg) { 8. return Integer.parseInt(arg); 9. } 10. }
11. class Utils {
12. int getInt(String arg) throws Exception 13. }
结果为: A. 42 B. 编译失败。 C. 无输出结果。 D. 运行时异常被抛出。 答案:A
17.现有:
1. interface Altitude { 2. //insert code here 3. }
和4个声明: int HIGH = 7;
public int HIGH = 7; abstract int HIGH = 7; interface int HIGH = 7;
分别插入到第2行,有多少行可以编译?
return 42;{ } A. 0 B. 1 C. 2 D. 3 E. 4 答案:C
18.类Teacher: class Teacher{
String name; float salary;
Teacher(String name){ this.name = name; }
Teacher(String name,float salary){ this.name = name; this.salary = salary; } }
执行语句Teacher t = new Teacher(“Tom”,2000.0f);后,字段salary的值是哪一项? A. 2000.0f B. 0.0f C. null; D. 2000
答案: A
19.Java语言中表达式10/3的结果是哪项? :3 默认整数 A. 3.3 B. 3.33 C. 3
D. 3.0 答案:C
20.Java语言中表达式-12>>3的结果是哪项?-2 ?????-12/(2*2*2)取整 A. -4 B. -9 C. -1 D. -2
答案: D
21.下列赋值语句正确的是哪一项? A. long val=6; B. int age = 23L; C. short x=1,y=2,z z=x+y; D. int a= ‘A’;
答案: D
22.假设有2个整数x和y,表达式x>=y ? x : y的含义是哪项? A. 求2个数的较大数 B. 求2个数的较小数 C. 把y的值赋给x D. 把x的值赋给y
答案: A
23.程序: class TestApp{
public static void main(String[] args){
for(int i=0;i<5;i++)
System.out.print(i+1); System.out.println(i); } }
上述程序运行后的结果是哪项? A. 123456 B. 123455 C. 123450
D. 编译错误 ??????????作用域,I 消失了
答案: D
24.程序: class TestApp{
public static void main(String[] args){
for(int i=0;i<10;i++){
if(i==3) break;
System.out.print(i);
} } }
程序运行后的输出是哪项? A. 0123 B. 012
C. 0123456789 D. 012456789
答案: B
25.程序: class TestApp{
public static void main(String[] args){
}
public int multiply(int… nums){ int result = 1; for(int x :nums) result *= x; return result; } }
程序运行后的输出是哪项? A. 14 B. 编译错误 C. 120 D. 24
答案: C
26.程序:
class TestReference{
public static void main(String[] args){
int x=2;
System.out.println(multiply(2,3,4,5));
TestReference tr = new TestReference(); System.out.print(x); tr.change(x); System.out.print(x);
}
public void change(int num){ num = num + 1; } //注意没有返回值 }
程序运行后的输出是哪项? A. 23 B. 21