求大神解答下这个java程序的答案为什么是这个,最好详尽一些。 10
publicclassTestOne{publicstaticvoidmain(String[]args){Fatherpapa=newFather();Sonzi=ne...
public class TestOne {
public static void main(String[] args){
Father papa = new Father();
Son zi = new Son();
papa = zi;
papa.test();
System.out.println(papa.x);
}
}
class Father{
int x=5;
public void test(){
System.out.println("this is father");
}
}
class Son extends Father{
int x=3;
public void test(){
System.out.println("this is son");
}
}
运行结果:this is son
5 展开
public static void main(String[] args){
Father papa = new Father();
Son zi = new Son();
papa = zi;
papa.test();
System.out.println(papa.x);
}
}
class Father{
int x=5;
public void test(){
System.out.println("this is father");
}
}
class Son extends Father{
int x=3;
public void test(){
System.out.println("this is son");
}
}
运行结果:this is son
5 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询