朋友遇到的面试题,供大家拍砖
class Base{
void iam(Base b){
System.out.println("i am base base");
}
void iam(Child b){
System.out.println("i am base child");
}
}
class Child extends Base{
void iam(Base b){
System.out.println("i am child base");
}
void iam(Child b){
System.out.println("i am child child");
}
}
public class Test{
public static void main(String[] args) {
Base[] test = new Base[]{new Child(), new Child()};
for (int i = 0; i < test.length; i++) {
test[i].iam(test[i]);
}
}
}
class Base{
void iam(Base b){
System.out.println("i am base base");
}
void iam(Child b){
System.out.println("i am base child");
}
}
class Child extends Base{
void iam(Base b){
System.out.println("i am child base");
}
void iam(Child b){
System.out.println("i am child child");
}
}
public class Test{
public static void main(String[] args) {
Base[] test = new Base[]{new Child(), new Child()};
for (int i = 0; i < test.length; i++) {
test[i].iam(test[i]);
}
}
}