class Father{
int i = 5;
public void p(){
i++;
System.out.println(i);
}
}
class Son extends Father{
int i=3;
public void p(){
i++;
System.out.println(i);
}
}
public class Demo4{
public static void main(String[] args){
Father father = new Father();
father.p();
System.out.println(father.i);
Son son = new Son();
son.p();
System.out.println(son.i);
Father fa_so = new Son();
fa_so.p();
System.out.println(fa_so.i);
}
int i = 5;
public void p(){
i++;
System.out.println(i);
}
}
class Son extends Father{
int i=3;
public void p(){
i++;
System.out.println(i);
}
}
public class Demo4{
public static void main(String[] args){
Father father = new Father();
father.p();
System.out.println(father.i);
Son son = new Son();
son.p();
System.out.println(son.i);
Father fa_so = new Son();
fa_so.p();
System.out.println(fa_so.i);
}
}
//Father fa_so = new Son();这样定义对象,以我现在的理解是:要单独操作成员变量,那么看父类的;
如果要调用方法,那么选择子类的成员方法。
等老师讲完这一部分,如果和我理解的不一样,那我会在后面说明。