example_4(继承)

继承:

public class Super {
    public static void main(String[]args){
        new son().f();
    }
}
class Father{
    public int value;
    public void f(){
        value=100;
        System.out.println("father"+value);
    }
}

class son extends Father{
    public int value;
    public void f(){
        super.f();//父亲函数    super就是父亲
        value=200;
        System.out.println("son"+value);
        System.out.println(value);
        System.out.println(super.value);
    }
}

 

posted @ 2022-03-23 15:51  Theext  阅读(28)  评论(0)    收藏  举报