Force invocation of base class method

后端 未结 4 1209
孤城傲影
孤城傲影 2020-12-12 00:11

The following code when run obviously prints out \"B1/A2/B2\". Now, is it possible for it to print \"A1/A2/B2\" instead (i.e. A#method2() should invoke method1() on A, not

4条回答
  •  眼角桃花
    2020-12-12 00:34

    I don't believe so; not if you're overriding method1() in a subclass. If you really required that behavior, you'd have to declare A.method1() as final, and you couldn't define it in B.

    It doesn't make sense to me to do this - you should reconsider your design if you think you need to!

提交回复
热议问题