How does inheritance in Java work?

前端 未结 6 1932
迷失自我
迷失自我 2020-12-09 21:23

We have next classes:

class Super {
    void foo() {
        System.out.println(\"Super\");
    }
}

class Sub extends Super {
    void foo() {
        super         


        
6条回答
  •  醉话见心
    2020-12-09 21:42

    when you write super.foo(); you are calling the superclass method.

    The foo method of class sub overrides the foo method of Super by adding an instruction to the super class method.

提交回复
热议问题