10) Parent p = new Parent(); 11) } 12) }
那些行将引起错误?
A 第3行 B 第6行 C 第7行 D 第8行
6. 编译下列代码的结果是? P ublic class SiteInfo{
String webSite=\public String getSite(){ return webSite; } } A.没有任何问题
B.编译器会报错误:':' expected for the statement in line 2. C.缺少main方法.
D.getSite()方法中的return webSite有问题
7. 给出下面代码段 1) public class Test { 2) int m, n; 3) public Test() {}
4) public Test(int a) { m=a; }
5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k; 8) j=0; k=0; 9) t1=new Test(); 10) t2=new Test(j,k); 11) } 12) }
哪行将引起一个编译时错误?
A line 3 B line 5 C line 6 D line 10
8. 对于下列代码: 1) class Person {
2) public void printValue(int i, int j) {//... } 3) public void printValue(int i){//... } 4) }
5) public class Teacher extends Person {
41
6) public void printValue() {//... } 7) public void printValue(int i) {//...} 8) public static void main(String args[]){ 9) Person t = new Teacher(); 10) t.printValue(10); 11) } 12)}
第10行语句将调用哪行语句??
A line 2 B line 3 C line 6 D line 7
9. 给定下面的Java程序段:
1) StringBuffer sb = new StringBuffer(\2) String s = new String(\3) sb.append(\4) s.append(\5) sb.insert(1, \6) s.concat(sb); 7) s.trim(); 下面那些描述是正确的:
A. 编译器在 line 1产生错误 B. 编译器在 line 2产生错误 C. 编译器在 line 3产生错误 D. 编译器在 line 4产生错误 E. 编译器在 line 5产生错误 F. 编译器在 line 6产生错误 G. 编译器在 line 7产生错误
10. 给定如下的代码: 1) public class Test { 2) int m, n; 3) public Test() {}
4) public Test(int a) { m=a; }
5) public static void main(String arg[]) { 6) Test t1,t2; 7) int j,k; 8) j=0; k=0; 9) t1=new Test();
42
10) t2=new Test(j,k); 11) } 12) }
下列哪一行会在编译时产生错误?
A. line 3 B. line 5 C. line 6 D. line 10
四、 程序填空题(10题)
1. ★下面程序运行,将输出什么结果________________ class ForLoop{
public static void main(String args[]){
int i=0,j=5; st: for(;;i++){
for(;;j--){
if(i>j)
break st;
}
}
System.out.println(\
}
}
答案:i=0 j=-1
2. ★ 下面程序运行,将输出j的值是__________ class Example{
public static void main(String args[]){
int x=4,j=0; switch(x){
case 1:j++; case 2:j++; case 3:j++; case 4:j++; case 5:j++; break; default:j++;
}
System.out.println(j);
} }
答案:2
43
3. 下面代码运行后得到baz的值是___________ class Example{
public static void main(String args[]){
String bar=new String(\String baz=new String(\String var=new String(\String c=baz; baz=var; bar=c; baz=bar;
System.out.println(baz);
}
}
答案:green
4. 写出下列代码执行的结果: public class Test1 {
public static void main(String[] args) {
for (int i=-2; i<2; i++) {
if (i==0) continue;
System.out.println(\
}
}
} 答案: i=-2 i=-1 i=1
5. 给定如下代码,程序输出的结果是: public class Test {
void printValue(int m){
do { System.out.println(\}
while( --m > 10 )
}
public static void main(String arg[]) {
int i=10;
Test t= new Test(); t.printValue(i);
44
}
} 答案:
The_value_is_10 6. 写出下列程序的结果 public class Test{
public static void main(String args[]){
String s1=”Henry Lee”; String s2=”Java Applet”; String s3=”Java”; String st;
if(s1.compareTo(s2)<0)
st=s2;
else
st=s1;
if(st.compareTo(s3)<0)
st=s3;
System.out.println(“big=”+st);
}
} 答案:
big=Java Applet
7. 写出下面程序运行的结果: import java.util.Arrays; public class SortArray {
public static void main(String args[]) {
String[] str = {\Arrays.sort(str);
for (int i=0; i System.out.print(str[i]+\ } } 答案: abs_class_length_size_ 8. 定义A,B如下: class A { int a=1; double d=2.0; 45