public class test1 {
public static void main(String args[]){
test1 a=new test1();
test2 b=new test2();
test1 a1=b;
System.out.println("test for a is :"+a.test());
System.out.println("test for a1 is :"+a1.test());
}
String test(){
return "test1";
}
}
class test2 extends test1{
String test(){
return "test2";
}
}
输出的结果是test for a is :test1
test for a1 is :test2
考察的根本在于调用时使用的是
public static void main(String args[]){
test1 a=new test1();
test2 b=new test2();
test1 a1=b;
System.out.println("test for a is :"+a.test());
System.out.println("test for a1 is :"+a1.test());
}
String test(){
return "test1";
}
}
class test2 extends test1{
String test(){
return "test2";
}
}
输出的结果是test for a is :test1
test for a1 is :test2
考察的根本在于调用时使用的是