|
一、写出下列程序段的输出结果:
1、public class Test {
public static void changeStr(String str){
str="welcome";
}
public static void main(String[] args){
String str="1234";
changeStr(str);
System.out.println(str);
}
}
运行结果:
1234
2、public class Test1{
static boolean foo(char c){
System.out.print(c);
return true;
}
public static void main(String[] argv){
int i=0;
for(foo('A'); foo('B')&&(i<2); foo('C')){
i++;
foo('D');
}
}
}
运行结果:
ABDCBDCB
二、选择题
1、class A{
protected int method1(int a,int b){
return 0;
}
}
Which two are valid in a class that extends class A? (Choose two)
(大概意思:A的子类中,下面哪两个方法可以通过编译?)
A. public int method1(int a, int b) { return 0; }
B. private int method1(int a, int b) { return 0; }
C. private int method1(int a, long b) { return 0; }
D. public short method1(int a, int b) { return 0; }
E. static protected int method1(int a, int b) { return 0; }
答案:AC [C不属于方法的重载]
2、public class Outer{
public void someOuterMethod(){
//Line 3
}
public class Inner{
}
public static void main(String[] argv){
Outer o=new Outer();
//Line 8
}
}
Which instantiates an instance of Inner?
(大概意思:下列Inner内部类的实例在程序中对应行创建正确的是?)
A. new Inner(); // At line 3
B. new Inner(); // At line 8
C. new o.Inner(); // At line 8
D. new Outer.Inner(); // At line 8//new Outer().new Inner()
答案:A |
|