Force invocation of base class method

后端 未结 6 414
庸人自扰
庸人自扰 2020-12-11 23:53

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

6条回答
  •  既然无缘
    2020-12-12 00:50

    Even I WAS looking for this solution. It seems its not possible. Changing the base class is not an option. i.e. assuming that base class is already written and you are deriving a class from it, there's nothing you can do in the derived class so that the base class calls its own methods and not overridden methods. if you are making an object of the derived class, base class will call overridden methods of derived class instead of calling its own methods. that's OOPS....

提交回复
热议问题