Java: Calling a super method which calls an overridden method

前端 未结 13 2319
有刺的猬
有刺的猬 2020-11-27 10:29
public class SuperClass
{
    public void method1()
    {
        System.out.println(\"superclass method1\");
        this.method2();
    }

    public void method2(         


        
13条回答
  •  独厮守ぢ
    2020-11-27 10:58

    You're using the this keyword which actually refers to the "currently running instance of the object you're using", that is, you're invoking this.method2(); on your superclass, that is, it will call the method2() on the object you're using, which is the SubClass.

提交回复
热议问题