初学者几道基础题目,谢谢
1.下面语句段的输出结果是什么?
int i = 9;
switch (i) {
default:
System.out.println("default");
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two"); }
A default
B default, zero
C error default clause not defined
D no output displayed
2、下面哪些选项将是下述程序的输出?
public class Outer{
public static void main(String args[]){
Outer: for(int i=0; i<3; i++)
inner:for(int j=0;j<3;j++){
if(j>1) break;
System.out.println(j+"and"+i);
}
}
}
A 0 and 0
B 0 and 1
C 0 and 2
D 0 and 3
E 2 and 2
F 2 and 1
G 2 and 0
3指出下列程序运行的结果
public class Example{
String str=new String("good");
char[]ch={'a','b','c'};
public static void main(String args[]){
Example ex=new Example();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
Sytem.out.print(ex.ch);
}
public void change(String str,char ch[]){
str="test ok";
ch[0]='g';
}
}
A good and abc
B good and gbc
C test ok and abc
D test ok and gbc
4.对于下列代码:
1) class Person {
2) public void printValue(int i, int j) {//... }
3) public void printValue(int i){//... }
4) }
5) public class Teacher extends Person {
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) }
第10行语句将调用哪行语句??
A line 2
B line 3
C line 6
D line 7